home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / ubas830.zip / UBHELP.XXX < prev    next >
Text File  |  1992-01-05  |  123KB  |  4,360 lines

  1. ;
  2. ; * UBASIC for IBM-PC version 8.30
  3. ;    User's manual for UBHELP system
  4.  
  5. ~~RunningUB
  6. Running UBASIC
  7.  
  8. Insert the UBASIC distribution diskette, then type
  9.  
  10.     UBIBM<Enter>
  11.  
  12. on the DOS command line.  (<Enter> is the large key engraved
  13. "Enter" or "Return" or a bent arrow.)  If your machine's
  14. processor is 80386, type
  15.  
  16.     UBIBM32<Enter>
  17.  
  18. instead for better performance.  To run the example program
  19. "PI.UB" on the distribution diskette, type
  20.  
  21.     LOAD "PI"<Enter>
  22.     RUN<Enter>
  23.  
  24. The program will prompt you to enter how many places you want
  25. pi to be displayed (10-2500).  Type for example
  26.  
  27.     1000<Enter>
  28.  
  29. Wait a few seconds.  Your screen will display 3.14159...
  30. to 1000 decimal places.  Type
  31.  
  32.     LIST<Enter>
  33.  
  34. to examine the program.  Finally, type
  35.  
  36.     SYSTEM<Enter>
  37.  
  38. to exit to the DOS.
  39.  
  40.  
  41. ~~NUMBERS
  42. NUMBERS
  43.  
  44.   UBASIC supports integers, rational numbers, real numbers
  45. and complex numbers.
  46.  
  47. 1-1. Integers
  48.   UBASIC supports a wide range of integers from -65536^542 to
  49. 65536^542 which is a number in a little more than 2600 figures
  50. in decimal expression.
  51. Results out of this range create an overflow.
  52. Hexadecimal integers can be entered as  '0x..' (not '&h..').
  53.  
  54. 1-2. Rational numbers
  55.   UBASIC allows calculations with rational numbers, only the
  56. type of value is limited to integer / integer. Numerator and
  57. denominator are marked off by '//'.
  58.  
  59. Ex:    a=2//3
  60.     a=3:b=5:c=a//b
  61.  
  62.   Expression may differ from the input, as rational numbers
  63. are memorized as an irreducible fraction.
  64.  
  65.   Since // has the same precedence as *, /, \, or @, the
  66. order of operations may not be the same as you expected.
  67. Use parentheses to avoid this.
  68.  
  69. Ex:    2\6//3 = 0
  70.     2\(6//3) = 1
  71.  
  72.   When a rational number is mixed with real or complex
  73. numbers, it is automatically converted to a real.  This also
  74. happens when it is the real part or the imaginary part of a
  75. complex number.
  76.   Rational arguments are automatically converted to reals in
  77. functions like SIN, EXP, etc.
  78.  
  79. 1-3. Real numbers
  80.   Real numbers are expressed as fixed point numbers.  The
  81. maximum amount of memory occupied by the integer part and the
  82. decimal part is fixed at 542 words.  The size of the decimal
  83. part is specified by the POINT statement.  The default value
  84. is 4, that is, 4 words are assigned to the decimal part and
  85. 538 words to the integer part.  The smallest positive real
  86. number is 65536^(-4), since 1 word is 65536.
  87.  
  88. 1-4. Complex numbers
  89.   UBASIC allows calculations with complex numbers as well as
  90. those with real numbers.  The maximum allowed size of a
  91. complex number is 541 words including both the real part and
  92. the imaginary part.  As the real part is usually about as
  93. large as the imaginary part, the maximum size of each part is
  94. 270 words, that is, 1300 digits in decimal notation.
  95.   Read the following examples carefully, since the expression
  96. of complex numbers in UBASIC is a little peculiar.
  97.  
  98.   The imaginary unit is represented by "#i".  Complex numbers
  99. are expressed as follows:-
  100.  
  101. numbers        1+#i, 1.23+2.34#i, 12345+23456.789#i
  102.             * is not necessary.
  103.         1.23+#i*2.34, 12345+#i*23456.789
  104.             * is necessary.
  105. variables, etc.    A+B*#i, Abc+#i*sin(x)
  106.             * is necessary.
  107.  
  108. Notes:
  109.   1/2#i is interpreted as 1/(2#i).  So the result is -0.5#i.
  110.   1/2*#i is interpreted as (1/2)*#i.  So the result is 0.5#i.
  111.   Similarly, 2^3#i is 2^(3#i) while 2^3*#i is (2^3)*#i.
  112.  
  113.   When complex numbers are used, set the WORD value to more
  114. than 4 * POINT(for example, if POINT = 10, then WORD must be
  115. more than 40).  Otherwise, overflow can easily occur for
  116. reasons of internal structure when a complex number is
  117. assigned to a long variable.
  118.  
  119.   There are 3 functions that return absolute values: ABS,
  120. ABSMAX, ABSADD.
  121.  
  122.     abs(z)    = sqrt(Re(z)^2+Im(z)^2)
  123.     absmax(z) = max{abs(Re(z)),abs(Im(z))}
  124.     absadd(z) = abs(Re(z))+abs(Im(z))
  125.  
  126.   ABS returns the ordinary absolute value, but it takes more
  127. time.  ABSMAX and ABSADD are recommended to check errors quickly.
  128.  
  129.   ARG(x) returns the argument of x.  The value returned is A,
  130. where -pi < A <= pi.
  131.  
  132.   UBASIC has the complex number versions of the following functions:
  133. EXP, LOG, SIN, COS, TAN, ATAN, SINH, COSH, SQRT, BESSELI, BESSELJ.
  134.  
  135.  
  136. << Notes for mixed types expressions >>
  137.   Different types of numbers can be used together in one
  138. expression.  Result type may vary with the order of the
  139. operations.
  140.  
  141. Ex:    1.0+1-1.0 = 1.0 (real)
  142.     1.0-1.0+1 = 1    (integer)
  143.  
  144.   This is because when a result of the calculation of reals
  145. and/or complex numbers is 0, it is converted to an integer.
  146.  
  147.   There are round-off errors caused by conversions from
  148. internal binary expression to decimal output.  These errors
  149. are typically seen in the expressions of '0'.  If the output
  150. is '0' it really is '0', while '0.0' and '-0.0' are nonzero
  151. values that are too small to be expressed.  Note that this
  152. occurs only for 0.  '1.0' may be equal to '1' or a little
  153. larger or smaller.  To know which, subtract 1 from it.  As a
  154. result of calculation, there is no essential difference
  155. between '1'(integer) and exact '1.0' (real), though the size
  156. of the internal memory required is different.  Naturally, '1'
  157. (integer) needs smaller memory and can be calculated faster.
  158.  
  159.  
  160. ~~VARIABLES
  161. VARIABLES
  162.  
  163.   UBASIC has three types of variables:-
  164.  
  165. 1) Short variables, such as A%, Foo_bah% (and arrays)
  166.   A short variable holds a one-word (16-bit) integer
  167. (-32767, ..., 32767).  Rational numbers, complex numbers, and
  168. strings cannot be assigned to a short variable.
  169.  
  170. 2) Long variables,  such as  A, Foo_bah (and arrays)
  171.   The size of long variables is specified by WORD statement.
  172.   It cannot be specified individually.
  173.  
  174. 3) EXTRA variables, such as  A#, Foo_bah# (and arrays)
  175.   Variables whose size is fixed at 542 words.
  176.  
  177.   A variable name is a letter, possibly followed by at most
  178. 15 letters, digits, and underscores(_).  Short and EXTRA
  179. variable names have a final "%" and "#" character, respectively.
  180. A variable name may not coincide with UBASIC statements/functions
  181. and it may not start with "fn" (which is the mark of user defined
  182. functions).
  183.   The first character is automatically converted to uppercase
  184. while the rest is left as it is.  Uppercase and lowercase
  185. letters are not distinguished.
  186.  
  187. Ex:    A, BC, MaximumElement, Maxscore%, Minscore(10)
  188.     Abcdefghi and ABCDEFGHIJ are regarded as the same.
  189.     NextOne, Step1, etc. are distinguished from  the
  190.     statements NEXT, STEP, etc.
  191.  
  192.   A simple variable and an array with the same name are
  193. distinguished.
  194.  
  195.   Arrays of up to three dimensions can be declared.  Array
  196. indices may be as large as 65534.  So the size of an array of
  197. short variables of one dimension is up to 128 KB.  The size of
  198. an array of two dimensions can be as large as the available
  199. memory.
  200.  
  201.   There is no need of EXTRA variables if the length of long
  202. variables is specified as 542 words.  EXTRA variables are used
  203. when a few large numbers occur among many relatively short long
  204. variables.
  205.  
  206.   Long variables and EXTRA variables can be assigned
  207. integers, rationals, reals, complex numbers, character strings
  208. and polynomials.
  209.   See appendix A for the internal expressions of numbers,
  210. strings and polynomials.
  211.  
  212.   An overflow occurs when the length of variable exceeds 542
  213. words in the process of calculation, or when a result
  214. exceeding the limit of the variable is assigned.
  215. In particular, in multiplication and division of real numbers,
  216. the intermediate results very often exceed 542 words.  This is
  217. because UBASIC executes the operation using all the
  218. significant figures and discards the lesssignificant ones
  219. afterwards.
  220.  
  221.   No more than 180 variables and arrays may be used
  222. simultaneously.
  223.  
  224.  
  225. ~~OPERATIONS
  226. OPERATIONS
  227.  
  228. 3-1. Operators
  229.  
  230.   Comparisons            =, >, <, <>, <=, >=
  231.   Addition, Subtraction        +, -
  232.   Multiplication, Division    *, /
  233.   Integer Division        \
  234.   Rational Division        //
  235.   Remainder            @
  236.   Power                ^
  237.  
  238. 3-2. Value of logical expression
  239.   In UBASIC, the value of logical expression is 1 when it is
  240. TRUE 0 when it is FALSE.  In conditional expressions, a
  241. nonzero value is regarded as TRUE.
  242. So:-
  243.     if A<>0 then ...
  244.         is equivalent to:
  245.     if A then ...
  246.  
  247.   This is valid also when A contains a real number.
  248. However, this short form is not recommended.
  249.  
  250. 3-3. Division of real numbers (/) and integers (\)
  251.  
  252.   Usual division is calculated up to the decimal place
  253. specified by POINT.  The digits beyond it are omitted.
  254. Integer division returns an integer quotient when both of
  255. the arguments are integers.  A real or complex argument
  256. creates an error. 
  257.   Remainder of integer division is contained by the system
  258. variable RES while remainder of real division is undefined.
  259.  
  260. Ex:    12345/100 is 123.45 (actually 123.449999...)
  261.     12345\100 is 123. Remainder is 45.
  262.  
  263.   If the remainder is 0, the result varies with "/" and "\".
  264.  
  265. Ex:    123/3 is 41.0, while 123\3 is 41.
  266.  
  267.   In the process of integer division A\B, the quotient is
  268. determined in such a way that the remainder is non-negative
  269. and numerically less than ABS(B).
  270.   This seems natural in division by positive numbers, but
  271. rather strange if a negative divisor is involved.  For
  272. instance, (-1)/100 is -1 and the remainder is 99.  So -1
  273. never becomes 0 by repeated integer division.  Take care when
  274. you check the conclusion of a loop.
  275.  
  276. 3-4. Division of rational numbers (//)
  277.  
  278.   Division of rationals returns a rational when both of the
  279. arguments are rationals.  Otherwise, it is the same as real
  280. division (/).
  281.  
  282. Ex:    (2//3)//3 is 2//9
  283.     (2//3)/3 is 0.2222...
  284.     0.5//2 is 0.25
  285.  
  286. 3-5. Calclulation of a remainder
  287.  
  288.   @ is the remainder of integer division.
  289.  
  290.   It is different from MOD in some languages since it is
  291. determined as above (Section 3-3.) if a negative number is
  292. involved.
  293.  
  294. The remainder of
  295.     integer \ integer
  296.     complex number with integer coefficient \ integer
  297.     polynomial \ polynomial
  298. just calculated is held by the system variable RES so that you
  299. do not need to use @.  @ is used when only the remainder is
  300. needed and the quotient is not needed.
  301.   Note that the value of RES must be used just after the
  302. calculation, as it is destroyed by other calculations.
  303.  
  304. 3-6. Power X^Y.
  305.  
  306.   Powers of integers, reals, complex numbers, rationals, and
  307. polynomials.
  308.   If Y is positive, the result is X to the Y .
  309.   The return value is exact if X is an integer, while it is
  310. an approximate value if X is a real.
  311.   If Y is 0, the result is 1 as a polynomial of degree 0 when
  312.  X is a polynomial, otherwise 1 as an integer regardless of
  313. the type of X.  0^0 is 1.
  314.   If Y is not zero and X is zero, the result is 0.
  315.   See appendix B for the algorithm in the case where Y is a
  316. real or a complex number.
  317.   X^Y^Z is usually interpleted as X^(Y^Z), but it is (X^Y)^Z
  318. in UBASIC.
  319.  
  320. 3-7. Combined operators
  321.  
  322.   Combined operators are borrowed from the C language.
  323.  
  324.     A+=B is equivalent to A=A+B.
  325.  
  326. This can save you the trouble of typing long variable names.
  327.  Use of the combined operator can also speed up a program,
  328. since the calculation of the internal address of an array is
  329. executed only once.  The right hand side is evaluated before
  330. the combined operation:-
  331.  
  332.     A*=B+C means A=A*(B+C), not A=A*B+C.
  333.  
  334.  
  335. ~~STRINGS
  336. CHARACTER STRINGS
  337.  
  338.   Like ordinary BASIC, UBASIC allows character strings.
  339. However, UBASIC has no string variables.  Use long variables
  340. or extra variables to assign character strings.  Since one
  341. character occupies 1 byte, a variable can contain twice as
  342. many characters as the WORD value: for example, 20 characters
  343. when the WORD value is 10.
  344.   Character strings are compared by ASCII code in
  345. lexicographic order.
  346.  
  347.  
  348. ~~POLYNOMIAL
  349. POLYNOMIALS
  350.  
  351.   UBASIC allows polynomials in one variable.
  352. There are two types of polynomials: polynomials with
  353. coefficients in integers modulo a prime (<= 65536) (we call
  354. them "modulo polynomials"), and normal polynomials.  In the
  355. former type we can handle polynomials up to about the 1000th
  356. degree, but in the latter type we can handle only polynomials
  357. of relatively lower degree (e.g. up to (1+X)^95).
  358.  
  359. 5-1. Entering of polynomials
  360.  
  361.   The variable of a polynomial is represented by "_X".
  362.  
  363. Ex:    A=1+2*_X+3*_X^2
  364.  
  365. However, the result is displayed with "X".
  366.  
  367. Ex:    A=1+2*_X+3*_X^2:print A
  368.         displays "3*X^2 + 2*X + 1".
  369.  
  370.   You may also use the function POLY to specify the coeffi-
  371. cients in order starting with the coefficient of degree 0.
  372.  
  373. Ex:    A=poly(1,2,3) is equivalent to the above example.
  374.  
  375.   To specify the coefficient of each degree, use COEFF.
  376.  
  377. Ex:    A=0:coeff(A,0)=1:coeff(A,1)=2:coeff(A,2)=3
  378.         is equivalent to the above examples.
  379.  
  380.   Note that the variables specified by COEFF have to contain
  381. a polynomial (or 0).
  382.   The value of the system variable MODULUS determines whether
  383. a polynomial is a modulo polynomial or a normal one.  If
  384. MODULUS is 0, it is a normal one and if MODULUS is a prime, it
  385. is a modulo polynomial.
  386.  
  387. 5-2. Calculation with polynomials
  388.  
  389.   The following caluculation are allowed with polynomials:-
  390.     Addition    +
  391.     Subtraction    -
  392.     Multiplication  *
  393.     Division    \
  394.     Remainder    @
  395.     Power        ^
  396.     Differential    diff
  397.     Value ( A(Y) )  val(A,Y)
  398. Note that the division is "\".
  399.  
  400.   The system variable RES contains the remainder after the
  401. division of polynomials.
  402.   Calculations with a normal polynomial and a modulo
  403. polynomial are not allowed.  Calculations with modulo
  404. polynomials create an error if the value of MODULUS is not as
  405. it was when the polynomials were entered.  In particular,
  406. calculations containing polynomials created under different
  407. values of MODULUS are not allowed.
  408.   VAL returns the value of the polynomial as evaluated for
  409. the given n.
  410.  
  411. Ex:    A=poly(1,1):print val(A,2)
  412.         displays "3".  (when MODULUS=0)
  413.  
  414.   A number and a polynomial of degree 0 are distinguished in
  415. the following cases:
  416.  
  417. polynomial / number
  418.             Each coefficient / number.
  419. polynomial / polynomial of degree 0
  420.             Error.
  421. polynomial \ number
  422.             Each coefficient \ number.
  423.             The value of RES is not valid.
  424. polynomial \ polynomial
  425.             of degree 0
  426.             Division of polynomials.
  427. polynomial @ number
  428.             Each coefficient @ number.
  429.             The value of RES is not valid.
  430. polynomial @ polynomial of degree 0
  431.             Remainder of division of polynomials.
  432. polynomial // number
  433.             Each coefficient // number.
  434. polynomial // polynomial of degree 0
  435.             Error.
  436.  
  437. Ex:    When A=_X^2+2*_X+3,
  438.     A\2  is  _X+1 and the value of RES is not valid.
  439.     A\poly(2) is (1//2)*_X^2+_X+(3//2) and the remainder is 0.
  440.  
  441. modulo polynomial / number
  442.             Each coefficient * inverse of number.
  443. modulo polynomial / polynomial of degree 0
  444.             Error.
  445. modulo polynomial \ number
  446.             Error.
  447. modulo polynomial \ polynomial of degree 0
  448.             Division of modulo polynomials.
  449. modulo polynomial @ number
  450.             Error.
  451. modulo polynomial @ polynomial of degree 0
  452.             Remainder of division of polynomials.
  453. modulo polynomial // number
  454.             Same as modulo polynomial / number.
  455. modulo polynomial // polynomial of degree 0
  456.             Error.
  457.  
  458. ~~PACKETS
  459. PACKETS
  460.  
  461.   Sometimes you may prefer to handle multiple data as one.
  462. UBASIC allows assigning multiple values to one variable.  We
  463. call this "a packet" (this is usually called "a list" , but
  464. UBASIC's "list" is too poor to call "a list").
  465.   It is recommended to assign a packet to an EXTRA variable
  466. so that the limit of its length is not modified by the WORD
  467. statement.  A long variable can be used if the WORD value is
  468. correctly set.
  469.  
  470.     A#=pack(23,"abc",1+3#i)
  471.       assigns an integer 23, a string "abc" and a complex
  472.       number 1+3#i to A#.
  473.  
  474.   To know the number of members PACKed in a packet, use LEN.
  475.  
  476.     When A#=pack(23,"abc",1+3#i), len(A#) is 3.
  477.  
  478.   To get a PACKed member, use MEMBER.
  479.  
  480.     When A#=pack(23,"abc",1+3#i), member(A#,1) is 23.
  481.  
  482.   Use MEMBER also to replace specified data.
  483.  
  484.     member(A#,3)="abc"
  485.       replaces the third member 1+3#i with a character
  486.       string "abc".
  487.  
  488.   A packet can be edited using LEFT, RIGHT, MID as well as a
  489. character string.  Consider 1 member as 1 character.  Note
  490. that the return value in this case is a packet.
  491.  
  492. Ex:    left(pack(2,4,6),1)  is  pack(2),
  493.     not 2 itself.  To get 2 itself, use MEMBER mentioned above.
  494.  
  495.   mid( ,2,*) is equivalent to "cdr" in LISP.
  496.   To add data to a packet, use "+".
  497.  
  498.     A#=A#+1000
  499.     or
  500.     A#+=1000
  501.       adds a new member 1000 to A#.  "+" is used also to
  502.       join 2 packets.
  503.  
  504.   The word length required by a packet is the sum of the word
  505. length of all the member + 1.
  506.  
  507.   In the case of A#=pack(23,"abc",1+3#i),
  508.  
  509. Integer 23:        data 1 word + attribute 1 word
  510. String "abc":        data 1 word + attribute 1 word
  511. Real part of complex number 1+3#i:
  512.             data 1 word + attribute 1 word
  513. Imaginary part of complex number 1+3#i:
  514.             data 1 word + attribute 1 word
  515. Complex number 1+3#i:    attribute 1 word
  516. Number of members (3 in this case):
  517.             1 word
  518. Total:            11 words
  519.  
  520.   (Actually, "attribute 1 word" of the packet itself is
  521. required.)
  522.  
  523.   So if a WORD value larger than 11 is specified, the packet
  524.  can be assigned to a long variable.
  525.  
  526.  
  527. ~~LABELS
  528. LABELS
  529.  
  530.   "Label" is a name given to the destination of GOTO and
  531. GOSUB.  It is recommended that labels be used instead of line
  532. numbers whenever convenient.
  533.  
  534.   The following two examples are equivalent:
  535. ....            ....
  536. 110 gosub 1000        110 gosub *ABCD
  537. ....            ....
  538. 1000 ....        1000 *ABCD:....
  539. ....            ....
  540. 1100 return        1100 return
  541.  
  542.   A label is a * followed by no more than 23 characters
  543. (letters, digits, ".", "_" and "?").  Upper and lower case are
  544. not distinguished.
  545.   Labels (such as *ABCD on line 1000 in the example above)
  546. must head their lines.  At most 100 labels may be used; the
  547. use of many labels slows the execution down.
  548.  
  549.   The RUN statement forms the list of labels.  So if the
  550. program is executed by GOTO, the results are unpredictable.
  551.  
  552.  
  553. ~~KEYS
  554.  
  555. 1. The function of special keys
  556.  
  557. DEL        Deletes the character under the cursor.
  558. BS        Deletes the character to the left of the
  559.         cursor.
  560. INS        Toggles insert mode on/off.  An underline
  561.         cursor is displayed in insert mode.
  562.  
  563. HOME        Moves the cursor to the home position
  564. CLR        Clears the screen
  565.  
  566. ESC        Cancels the listing of file choices in
  567.         commands such as LOAD, RUN, etc.
  568.  
  569. Arrow keys    Move cursor
  570.  
  571. 2. Editing Control Keys
  572.  
  573.   "Control-X" means to hit "X" while pressing the control key
  574.  at the left end of the keyboard.
  575.  
  576. Control-E:  Cursor up
  577. Control-X:  Cursor down
  578. Control-S:  Cursor left
  579. Control-D:  Cursor right
  580.  
  581. Control-Z:  Scroll up
  582. Control-W:  Scroll down
  583.  
  584. Control-R:  Page down
  585. Control-C:  Page up
  586.  
  587. Control-A:  Cursor leftmost
  588. Control-F:  Cursor rightmost
  589. Control-Q:  Cursor home(=HOME)
  590.  
  591. Control-L:  Clear the screen(=CLR)
  592. Control-B:  Delete lines below cursor
  593. Control-T:  Delete left of cursor
  594. Control-Y:  Delete right of cursor
  595. Control-G:  Delete character at cursor (=DEL)
  596. Control-H:  Delete character left of cursor (=BS)
  597. Control-O:  Insert a line
  598.  
  599. Control-V:  Insert/Overwrite toggle(=INS)
  600.         Underline cursor is displayed in the insert mode.
  601.  
  602. Control-C:  Halt execution, LIST, VXREF, etc. 
  603.         (Control-BREAK is recommended)
  604. Control-S:  Halt/Restart display
  605.  
  606. Control-BREAK: Halt execution. More sensitive than CTRL-C.
  607.  
  608. Control-N: In some versions of MS-DOS, this means "printer
  609. line feed" and in some cases, (especially when the printer is
  610. ON and off-line) the execution is halted and key inputs are
  611. not accepted.  To cancel this, turn off the printer or
  612. make it on-line.
  613.  
  614.  
  615. 3. Function Keys
  616.  
  617.   You may modify the settings of function keys using KEY.
  618.   Default settings are as follows:
  619.  
  620. f1    load "        f6    save "
  621. f2    dir "*.UB"    f7    xref
  622. f3    auto        f8    append "
  623. f4    list        f9    edit
  624. f5    run        f10    cont
  625.  
  626.  
  627. ~~SUBROUTINE
  628. SUBROUTINES AND FUNCTIONS
  629.  
  630.   The biggest defect of normal BASIC is the difficulty of
  631. making a program independent.  For example, if you are going
  632. to use a FOR-NEXT loop in a subroutine, you may find it
  633. difficult to choose the name of the loop variable.
  634. Because of this problem, it is almost impossible to make a
  635. useful program into a module.  UBASIC offers some ways to
  636. solve this problem.
  637.  
  638. Passing Arguments
  639.  
  640.   Arguments can be passed to subroutines.
  641.  
  642.      10    A=1:B=2:C=0
  643.      20    gosub *MAX(A,B,&C)
  644.      30    print C
  645.      40    end
  646.     100    *MAX(X,Y,&Z)
  647.      110      if X>=Y then Z=X else Z=Y
  648.     120    return
  649.  
  650.   At the beginning of the subroutine MAX, the values of
  651. variables A and B are passed to the different variables X and
  652. Y (call by value).  As X and Y are variables valid only in the
  653. subroutine MAX (local variables), changing of their values
  654. does not affect the main routine.  The variable C with "&" is
  655. regarded as the same as Z in the subroutine MAX (call by
  656. reference).  So if you change the value of Z in the subroutine
  657. MAX, the value of C also changes so that you can return the
  658. result to the main routine.  This condition is initialized by
  659. the RETURN in line 120.
  660.  
  661.   The format is different from those in QUICK BASIC and TURBO
  662. BASIC.
  663.  
  664. Limitations:
  665.     A simple short variable cannot be passed by reference.
  666.     That is, gosub *ABC(&A%) is not allowed.
  667.     A member of an array cannot be passed by reference.
  668.     That is, gosub *ABC(&A(1)) is not allowed.
  669.  
  670. User defined functions
  671.  
  672.   A function that extends to multiple lines can be defined.
  673.  
  674.      10    A=1:B=2
  675.      20    C=fnMAX(A,B)
  676.      30    print C
  677.      40    end
  678.     100    fnMAX(X,Y)
  679.     110      if X<Y then X=Y
  680.     120    return(X)
  681.  
  682.   As above, "fn" is required before the function name.  The
  683. return value of the function is placed between "()" after
  684.  "return".  The return value can be an expression.  In the
  685. above example, the function changes the value of X.  Note that
  686. this does not affect the main routine.
  687.  
  688.   You may call functions and subroutines LOADed into memory
  689. in direct mode without RUNning the program.  For example, if
  690. you LOAD the program "GENSHI" and type "? .genshi(13)", "2" is
  691. displayed ("?" and "." are abbreviations of "print" and "fn"
  692. respectively.)
  693.  
  694.   So if you collect frequently used subroutines/functions and
  695. make them into one program, you have only to LOAD it to use
  696. the subroutines/functions as you like in direct mode.  This
  697. will serve you as an electronic calculator.
  698.  
  699.   A user defined function itself can be passed to subroutine/
  700. function as an argument.  See the "Guide" or the sample program
  701. "Simpson" for an example.
  702.  
  703. Local Variables
  704.  
  705.   Local variables are variables valid only in a subroutine/
  706. function.
  707.  
  708.      10    for I=1 to 10
  709.      20      gosub *ABC(I)
  710.      30    next
  711.      40    end
  712.     100    *ABC(X)
  713.     110      local I
  714.     120      for I=1 to X
  715.     130        print X;
  716.     140      next
  717.     150      print
  718.     160    return
  719.  
  720.   I is declared as a local variable in line 110.  This I is
  721. distinguished from I in the main routine until RETURN.  The
  722. value is initialized to 0 by the LOCAL declaration.  The
  723. arguments of a subroutine/function mentioned above are also
  724. regarded as local variables.
  725.  
  726.   The beginning of a subroutine/function must be in the
  727. following format:
  728.  
  729.     Declaration of the subroutine/function.
  730.     Declarations of local variables beginning with LOCAL.
  731.     (Multiple lines are allowed.)
  732.     Declarations of local arrays beginning with DIM.
  733.     (Multiple lines are allowed.)
  734.  
  735.   The latter two may be placed in reverse order or
  736. alternately.  Other statements other than comments are not
  737. allowed in the middle of these declarations.
  738.  
  739. Limitations:
  740.     The maximum depth of recursive calls is up to 40.
  741.     Local labels are not available.  So when several
  742.     user defined functions are APPENDed, an error occurs
  743.     if these functions have the same label.
  744.  
  745.  
  746. ~~EMA-arrays
  747. EMA-array
  748.  
  749.   Expanded Memory usable for optional Arrays.
  750.  
  751.   Their names are ema(0;i,j), ema(1;i,j),..., ema(15;i,j) only.
  752. 0; can be omitted.
  753.  
  754. Limitation:
  755.     1 or 2 dimensional.
  756.     cannot be passed to subroutines as parameters.
  757.     cannot be preserved by freeze command.
  758.     cannot be erased.
  759.     cannot be handled by vlist, vxref, vchg.
  760.     each indice must be less than 65535.
  761.     (from v8.24 : CAN be declared as local variables.)
  762.  
  763. 1) Install the Expanded Memory Manager(satisfying LIM-EMS4.0)
  764.   in your DOS.
  765.   Usually add a line like :
  766.     device = emm.sys
  767.   to the config.sys file.
  768.    
  769. 2) Decide the size of an element.
  770.   Default size is same as that of long variables.
  771.   To change the size do:
  772.     emaword 100
  773.    each element of EMA is 100 words long.
  774.  
  775. 3) Decide the size of an array
  776.     dim ema(0;9,99)
  777.   2 dimensional, 1st indices are from 0 to 9, 2nd indices
  778.   are from 0 to 99.
  779.  
  780. Sample:
  781.      10    emaword 10
  782.      20    read N
  783.      30    dim ema(0;N-1,N-1)
  784.      40    dim ema(1;N-1,N-1)
  785.      50    gosub *ReadEma(0)
  786.      60    gosub *ReadEma(1)
  787.      70    data 3
  788.      80    data 1,2,3,4,5,6,7,8,9
  789.      90    data 3,4,5,6,7,2,3,4,5
  790.     100    '
  791.     110    gosub *DispEma(0):print
  792.     120    gosub *DispEma(1):print
  793.     130    gosub *AddEma(0,1)
  794.     140    gosub *DispEma(0)
  795.     150    end
  796.     160    '
  797.     170    *ReadEma(A)
  798.     180      local I,J
  799.     190      for I=0 to N-1
  800.     200        for J=0 to N-1
  801.     210          read ema(A;I,J)
  802.     220        next
  803.     230      next
  804.     240    return
  805.     250    '
  806.     260    *AddEma(A,B)
  807.     270      local I,J
  808.     280      for I=0 to N-1
  809.     290        for J=0 to N-1
  810.     300          ema(A;I,J)+=ema(B;I,J)
  811.     310        next
  812.     320      next
  813.     330    return
  814.     340    '
  815.     350    *DispEma(A)
  816.     360      local I,J
  817.     370      for I=0 to N-1
  818.     380        for J=0 to N-1
  819.     390          print ema(A;I,J);
  820.     400        next:print
  821.     410      next
  822.     420    return
  823.  
  824. Note:    Some of block commands are usable:
  825. Ex:    block ema(0;1,*)=123
  826.     block ema(0;*,*)+=block ema(1;*,*)
  827.     clr, neg, swap block ema( ) are also usable.
  828.  
  829. Note:    We recommend you to use normal arrays at first and
  830.     compute for small parameters.  After debugging the
  831.     program, you save the program in the ASCII mode(use
  832.     asave) and replace the names of normal arrays by
  833.     ema(?;  using your text-editor.
  834.       And then enlarge the size of parameters.  We think
  835.     you will be confused if you will use EMA-arrays from
  836.     the beginning.
  837.  
  838.  
  839. ~~RandomFile
  840. Random Files
  841.  
  842.   Disk files are usable for optional arrays.
  843. Their names are file1, file2, file3 only.
  844.  
  845. Limitation:
  846.   1 dimensional.
  847.  
  848. 1) make a new file
  849.     open "ABC" as file1(1000) word 100
  850. uses file "ABC" for the array named file1.  The indices
  851. are from 0 to 1000.  Size of each element is 100 words.
  852.  
  853. 2) read/write
  854.     file1(10)=123
  855.     print file1(5)
  856.  
  857. 3) close file
  858.     close file1
  859.  
  860. 4) use again
  861.     open "ABC" as file1
  862.  
  863. Sample:
  864.      10    'GENWRITE version 2.0
  865.      20    open "GENTBL" as file1(6542) word 1
  866.      30    file1(0)=0:file1(1)=1
  867.      40    for I=2 to 6542
  868.      50      print I,
  869.      60      P=prm(I)
  870.      70      file1(I)=fnGenshi(P)
  871.      80    next
  872.      90    end
  873.     100    '
  874.     110    fnGenshi(P)
  875.     120      local Gen=1,N=P-1,Nw,Div,Sw%
  876.     130      if P=2 then return(1)
  877.     140      if or{P<3,len(P)>32,prmdiv(P)<P} then return(0)
  878.     150      repeat
  879.     160        inc Gen:Nw=N:Sw%=1
  880.     170        repeat
  881.     180          Div=prmdiv(Nw)
  882.     190          repeat:Nw=Nw\Div:until res:Nw=Nw*Div+res
  883.     200          if modpow(Gen,N\Div,P)=1 then Sw%=0:Nw=1
  884.     210        until Nw=1
  885.     220      until Sw%
  886.     230    return(Gen)
  887.  
  888.  
  889. ~~UserProg.
  890. User Program
  891.  
  892.   Machine language programs can be put in predeclared arrays of
  893. Short variables and called by array names.  The program starts
  894. at 0100H on the array's segment.  It must be of .COM type with
  895. extension .UBB.  Arguments are passed via either variables or
  896. the first 28 elements of the array.  The memory map, after the
  897. program is BLOADed and the arguments set (by BLOAD or CALL),
  898. is as follows:
  899.  
  900. 0000H-001FH    Size of the array etc.  Do not rewrite this area.
  901. 0020H-003FH    0th through 15th elements of an array, which can
  902.         be used to pass arguments.
  903. 0040H-0041H    Byte size of Long Variables
  904.         ((value specified by WORD) * 2 + 2)
  905. 0042H-0043H    Byte size of EXTRA Variables
  906. 0044H-0045H    Offset of the work area that holds the current
  907.         position of the calculation stack.  Segment is SS.
  908. 0080H-00FFH    Offset and segment of 1st argument, offset and
  909.         segment of 2nd argument, ...(addresses of at most
  910.         32 arguments, each 4 bytes long)
  911.  
  912.   The segment:offset pairs for the arguments may be omitted if
  913. the values are unchanged.  If you omit them, either use empty
  914. parentheses or successive commas.  When the routine is called,
  915. the registers are such that DS = ES = SS <> CS.  Use far
  916. returns.  Do not change DS, ES, SS, BP, and the string
  917. direction flag.
  918.  
  919. Ex1:
  920.  
  921.   This example clears the 0th through 9th elements of an array.
  922. The program name is CLR10, say.  The main program contains the
  923. three lines,
  924.  
  925.     DIM CL%(150)
  926.     BLOAD "CLR10", CL%()
  927.     CALL CL%(X%(0))
  928.  
  929. When the user program is called, the address of the 0th
  930. element of the array is in CS:0080H.  The source program would
  931. be as follows.  MAKEUBB CLR10 makes an executable program.
  932. MASM and LINK are needed.
  933.  
  934. ;SAMPLE FOR MAKING USER PROGRAM
  935. CODE    SEGMENT
  936.     ASSUME  CS:CODE,DS:CODE
  937.  
  938.     ORG    100H
  939. START:
  940.  
  941. CLR10    PROC    FAR        ;make it a PROC FAR to generate
  942.                 ;RETF code
  943.     MOV    BX,80H
  944.     LES    DI,CS:[BX]    ;get segment:offset of 0th element
  945.                 ;of the array
  946.     MOV    CX,10
  947.     XOR    AX,AX
  948.     REP    STOSW
  949.     MOV    AX,SS        ;recover DS,ES,BP.
  950.     MOV    ES,AX        ;DS,ES may be set equal to SS
  951.     RET
  952.  
  953. CLR10    ENDP
  954.  
  955. CODE    ENDS
  956. END    START
  957.  
  958. Ex2:
  959.  
  960.   To call UBASIC86's calculation routine from user programs,
  961. put necessary arguments onto the calculation stack; see UB.MAC
  962. macro definition file.
  963.  
  964.   PUSH(@PUSH) and POP(@POP) do not allow Short Variables.
  965.  
  966. For the example let's make a program doing:
  967.   "For the variables A, B, C, calculate C=A+B or C=A-B according to
  968.    the 0-th element of the array."
  969.  
  970. UBASIC program is:
  971.  
  972.    10   'addsub
  973.    20   'sample for machine language program
  974.    30   '
  975.    40   dim AddSub%(200)    reserve user program area
  976.    50   bload "addsub",AddSub%(A,B,C)
  977.                load user program and set parameters
  978.    60   A=123:B=234
  979.    70   AddSub%(0)=0        store a value to 0-array element
  980.    80   call AddSub%()        call user program
  981.    90   print A,B,C
  982.   100   AddSub%(0)=1
  983.   110   call AddSub%()
  984.   120   print A,B,C
  985.   130   end
  986.  
  987. Assembly program is:
  988.  
  989. ;addsub.asm
  990.  
  991.     include    UB.MAC        read macro definition file
  992.  
  993.     mov    bx,AR0
  994.     mov    ax,cs:[bx]    get the value of 0-th element
  995.     cmp    ax,1
  996.     jb    addAB
  997.     je    subAB
  998.     hlt
  999.  
  1000. addAB:
  1001.     @push    v1    push 1st parameter to calc_stack
  1002.     @push    v2         2nd
  1003.     @add        add them
  1004. getC:
  1005.     @pop    v3    send the result to 3rd parameter
  1006.     mov    ax,ss
  1007.     mov    ds,ax
  1008.     mov    es,ax
  1009.     retf
  1010.  
  1011. subAB:
  1012.     @push    v1
  1013.     @push    v2
  1014.     @sub
  1015.     jmp    getC
  1016.  
  1017. code    ends
  1018. end    start
  1019.  
  1020. ü@"makeubb addsub" will tranlate this assembly program to 
  1021. object program.  MASM and LINK are needed.  For other 
  1022. assemblers and linkers, rewrite the makeubb.bat file.
  1023.  
  1024.  
  1025. ~~Redirect
  1026. Output Redirection
  1027.  
  1028.   Output of PRINT/LPRINT statements can be redirected and
  1029. pluralized.
  1030.  
  1031. Ex:    PRINT = PRINT + LPRINT + "ABC".
  1032.  
  1033.    This makes PRINT statements to output to the screen, printer,
  1034. and file "ABC" until another such command or NEW or LOAD is
  1035. executed.  The PRINT#1 outputs are binary whereas the command
  1036. above outputs to "ABC" in the text (ASCII) mode.  Use SPC or
  1037. TAB rather than LOCATE and LLOCATE when redirecting to files.
  1038. The right-hand sides of "PRINT =" and "LPRINT =" must be
  1039. distinct.
  1040.  
  1041.  
  1042. ~~AutoExec.
  1043. Automatic Execution
  1044.  
  1045.   To automatically LOAD ECMX and factorize 3^33 + 1 and 6^66 + 1,
  1046. make the file "TEST":
  1047.  
  1048.     LOAD "ECMX"
  1049.     PRINT=PRINT+"MEMO"
  1050.     RUN
  1051.     3^33+1
  1052.     6^66+1
  1053.     0
  1054.     SYSTEM
  1055.  
  1056.   Then type UBIBM <TEST on the DOS command line.  Note that the
  1057. keyboard is disabled.
  1058.  
  1059. UBASIC86's output cannot be redirected by UBIBM >TEST1.
  1060.  
  1061.  
  1062. ~~ASC<->BIN
  1063. ASCII <-> BINARY data conversion
  1064.  
  1065.   ASCII from/to BINARY data conversion is done by input/output
  1066. redirection.
  1067.  
  1068. ABC(=BINARY) -> XYZ(=ASCII)
  1069.     10    open"ABC" for input as #1
  1070.     20    print=print+"XYZ"
  1071.     30    while not eof(1)
  1072.     40      input #1,A
  1073.     50      print A
  1074.     60    wend
  1075.     70    close #1
  1076.     80    print=print
  1077.     90    end
  1078.  
  1079. XYZ(=ASCII) -> ABC(=BINARY)
  1080.     10    open"ABC" for output as #1
  1081.     20    input="XYZ"
  1082.     30    loop
  1083.     40      input A
  1084.     50      print #1,A
  1085.     60    endloop
  1086.   This stops at the line 40 when this encounts the file end.
  1087. But don't care.
  1088.  
  1089. Type:
  1090.     close #1:input=input:end
  1091. to finish the conversion safely.
  1092.  
  1093.  
  1094. ~~Codes
  1095. Code of Numbers.
  1096.  
  1097. Short Variables -- The most significant bit represents the
  1098. sign, and the remaining 15 bits represent the absolute value.
  1099. There is no -32768.
  1100.  
  1101. Long and EXTRA Variables -- the least significant 13 bits
  1102. (currently only 9 bits) of the least significant word
  1103. represent the number of effective word, the next bit is the
  1104. complex flag and the next if the fraction flag,and the most
  1105. significant bit is the sign.  The absolute value begins with
  1106. the next word.
  1107.   The actual length is one plus the length specified by WORD;
  1108. thus an EXTRA Variable occupies 543 words.
  1109.  
  1110.   For example, 1.5 is represented as follows when POINT = 2.
  1111. 4003H, 0000H, 8000H, 0001H
  1112. <- less significant    more significant ->
  1113.  
  1114. Also , 1.5+2#i is represented as follows.
  1115. 2006h,4003H, 0000H, 8000H, 0001H, 0001H, 0002H
  1116. (1)(2) (3)             (4)
  1117. (1) complex flg on(sign flg and fraction flag must be off)
  1118. (2) effective words
  1119. (3) start of real part
  1120. (4) start of imaginary part
  1121.  
  1122. Files -- Numbers in files are formatted as Long and EXTRA
  1123. Variables represented as above.
  1124. The first 8 words of a file contains various information.
  1125.  
  1126. Arrays --
  1127. 0000H(WORD)    Dimension.
  1128. 0002H(WORD)    Not Used.
  1129. 0004H(WORD)    Size of the 1st dimension.
  1130. 0006H(WORD)    Number of elements per each 1st index.
  1131. 0008H(WORD)    Size of the 2nd dimension.
  1132. 000AH(WORD)    Number of elements per each combination of 1st
  1133.         & 2nd indices
  1134. ...
  1135. 001CH(WORD)    Size of the 7th dimension.
  1136. 001EH(WORD)    Must be 1.
  1137.  
  1138.   The current version supports only 3 dimensons.
  1139.  
  1140.  
  1141. ~~Functions
  1142. Built-In Functions
  1143.  
  1144.   Note that divisions are truncated, not rounded.
  1145.  
  1146. POWER -- X^Y
  1147. If Y=0 then answer=1. Otherwise if X=0 then answer=0.
  1148. If Y is a positive integer, the repeated squaring method is
  1149. used.
  1150. If Y is a negative integer, (1/X)^(-Y) is calculated as above.
  1151. If Y is a real number, it is done as above for the integer
  1152. part and for the rest is done by the combination of EXP and
  1153. LOG.
  1154. If Y is a complex number, EXP(LOG(X)*Y) is calculated.
  1155.  
  1156. ISQRT -- Uses Newton's algorithm:  Set t to the argument x.
  1157. Then repeat replacing t with (t + x \ t) \ 2 until t does not
  1158. decrease.  This gives the integer part of the square root of
  1159. x.
  1160.  
  1161. SQRT -- Same as above, with \ replaced by /.
  1162. If X is negative then calculates the square root of -x and
  1163. multiplies #i.
  1164. If X is complex(X=A+B*#i) then
  1165.   if A>=0 then
  1166.     Real part =sqrt{(abs(X)+A)/2}
  1167.     Imag part = B/(2*Real part)
  1168.   else
  1169.     Imag part =sqrt{(abs(X)-A)/2}
  1170.     Real part = B/(2*Imag part)
  1171.  
  1172. SIN, COS  -- Adds the Taylor series until the summand
  1173. vanishes.
  1174. The parameter X is reduced in 0<=x<#pi/4 before calculating
  1175. the series.
  1176. If X is complex(X=A+B*#i) then
  1177.     sin(X)=sin(A)*cosh(B)+cos(A)*sinh(b)*#i
  1178.     cos(X)=cos(A)*cosh(B)+sin(A)*sinh(b)*#i
  1179.  
  1180. TAN = SIN/COS
  1181.  
  1182. ATAN -- sum of {(-1)^n}X^(2n+1)/(2n+1)
  1183. The parameter X is reduced to less than 1/8 by using following
  1184. formulas:
  1185.     pi/2-atan(1/X)
  1186.     atan(X)=atan(1/2)+atan(2X-1/X+2)
  1187.     atan(X)=atan(1/4)+atan(4X-1/X+4)
  1188.     atan(X)=atan(1/4)-atan(1-4X/X+4)
  1189.   UBASIC has atan(1/2) and atan(1/4) as system constants.
  1190. If X is complex then use
  1191.     atan(X)=log{(#i-X)/(#i+X)}/2#i
  1192.  
  1193. COSH -- (exp(x)+1/exp(x))/2
  1194.  
  1195. SINH -- (exp(x)-1/exp(x))/2
  1196.  
  1197. EXP -- Adds the Taylor series until the summand vanishes for
  1198. 0<= x <log(2)/2.
  1199. Generally, when x = n*log(2) +- y, (0<=y<log(2)/2), exp(+-y)
  1200. is calculated as above and is shifted by n bits.
  1201. If X is complex(X=A+B*#i) then
  1202. exp(X)=exp(A)*(cos(B)+#i*sin(B)).
  1203.  
  1204. LOG -- For 1 <= x < 2, let y = (x-1) / (x+1); repeat adding
  1205. (2 / (2n+1)) * y ^ (2n+1) to y until the summand vanishes.
  1206. For other values of x, first multiply or divide x by 2
  1207. repeatedly, then follow the algorithm above, then subtract or
  1208. add the suitable multiple of log(2).
  1209. If X is complex(X=A+B*#i) then
  1210. log(X)=log(abs(X))+#i*atan(B,A).
  1211. Where,
  1212.   atan(B,A)    = sgn(B)*pi/2    if A=0
  1213.         = atan(B/A)    if A>0
  1214.         = atan(B/A)+pi    if B>=0>A
  1215.         = atan(B/A)-pi    if A,B<0 .
  1216. Thus atan(B,A) takes its value larger than -pi less or equal
  1217. to pi.
  1218.  
  1219. ABS --- Absolute value of the complex number  z  is by
  1220. definition
  1221.     sqrt(Re(z)^2+Im(z)^2).
  1222. To minimize error, we shift-up  z  by POINT words and shift-
  1223. down the result when Re(z) and Im(z) are both less than 1,
  1224.  
  1225. BESSEL --- using simply their power series:
  1226.     BesselI(k,x)=sum of (x/2)^(2*n+k)/(n!*(n+k)!)
  1227.     BesselJ(k,x)=sum of (-1)^n*(x/2)^(2*n+k)/(n!*(n+k)!)
  1228.  
  1229. ~~!
  1230. !(n)
  1231. See:    Factorial.
  1232.  
  1233. ~~_X
  1234. _X
  1235.     Represents the variable when a polynomial is entered.
  1236.     This is used to distinguish a polynomial from other
  1237.     expressions.
  1238. Ex:    1+2*_X+3*_x^2
  1239.  
  1240.         The following piece of code will convert a polynomial
  1241.         entered using "X" to the necessary form using "_X" in 
  1242.         a program in which a polynomial is to be entered:
  1243.  
  1244.     100    X=_X
  1245.     110    strinput "f(x)=";W#
  1246.  
  1247. ~~#E
  1248. #E
  1249.     The base of natural logarithms, #e = exp(1).
  1250.     The precision is specified by the POINT command and is no
  1251.     more than 541 words.
  1252.     Assign it to a variable, rather than evaluating it many
  1253.     times.
  1254. Out:    real.
  1255. Ex:    print #E    result: 2.7182...
  1256.  
  1257. ~~#EPS
  1258. #EPS
  1259.     The smallest positive number that can be represented under
  1260.     the current POINT setting.  Use 10 or more times #eps for
  1261.     the convergence limit of Newton's method.
  1262. Out:    real.
  1263.  
  1264. ~~#EULER
  1265. #EULER
  1266.     Euler's constant, #euler = 0.5772...
  1267. Out:    real.
  1268.  
  1269. ~~#PI
  1270. #PI
  1271.     #pi = 3.14....
  1272.     The precision is specified by the POINT command and is no
  1273.     more than 541 words.  Assign it to a variable, rather than
  1274.     evaluating it many times.
  1275. Note:    Use PI(x) to get a multiple of #PI.
  1276. See:    PI.
  1277.  
  1278. ~~ABS
  1279. ABS(x)
  1280.     Absolute value of x.
  1281. Inp:    number.
  1282. Out:    integer, rational, real.
  1283. Ex:    print abs(1+2#i)    result: 2.2360...
  1284.  
  1285. ~~ABSADD
  1286. ABSADD(x)
  1287.     abs(Re(x)) + abs(Im(x)).
  1288. Inp:    number.
  1289. Out:    integer, rational, real.
  1290. Ex:    print absadd(1+2#i)    result: 3
  1291.  
  1292. ~~ABSMAX
  1293. ABSMAX(x)
  1294.     max{abs(Re(x)), abs(Im(x))}.
  1295. Inp:    number.
  1296. Out:    integer, rational, real.
  1297. Ex:    print absmax(1+2#i)    result: 2
  1298.  
  1299. ~~ALEN
  1300. ALEN(x)
  1301.     Number of decimal digits in the integer part of abs(x).
  1302. Note:    Use it with LOCATE, SPC, TAB to format output.
  1303. Inp:    integer.
  1304. Out:    integer.
  1305. Ex:    alen(0) = alen(9) = 1,  alen(-123/10) = 2.
  1306.  
  1307. ~~AND
  1308. AND{expression1,expression2, ...}
  1309.     Logical product.
  1310.     1 if all the expressions are nonzero, 0 otherwise.
  1311. Inp:    expressions.
  1312. Out:    integer(0 or 1).
  1313. Ex:    if and{A,B,...} then
  1314.         when the part between {} is long, use ':' like this:
  1315.     if and{A,
  1316.       :B,
  1317.       :...}
  1318.     :then
  1319.  
  1320. ~~APPEND
  1321. APPEND "program_name"
  1322.     Reads a program and appends it at the end of the current
  1323.     program.  The appended program is automatically renumbered.
  1324.     You cannot insert a program in the middle of the current
  1325.     program.
  1326.     A list of programs is displayed if no program name is given.
  1327.     Choose a program with the arrow keys and <ENTER>.
  1328. See:    LOAD, SAVE, VCHG, VLIST, VXREF.
  1329.  
  1330. Ex:    open "file_name" for APPEND as #n
  1331. See:    OPEN.
  1332.  
  1333. ~~ARG
  1334. ARG(x)
  1335.     Argument of x.
  1336. Inp:    number.
  1337. Out:    real y (-pi < y <= pi).
  1338. Ex:    print arg(1+2#i)    result: 1.1071...
  1339.  
  1340. ~~AS
  1341. AS
  1342. See:    OPEN.
  1343.  
  1344. ~~ASAVE
  1345. ASAVE "filename"
  1346.     Saves the current program on to a disk in the standard
  1347.     DOS text-file form(=ASCII form).
  1348. Note:    A program in ASCII form can be exchanged between UBASIC
  1349.     and your favorite editor which is more convenient for
  1350.     writing a large program.
  1351.     As intermediate code may vary with versions, ASCII form
  1352.     is recommended if you want to keep a program for a long
  1353.     time.
  1354.     If no file name is give, the current date and time are
  1355.     used as the program name.
  1356. See:    SAVE.
  1357.  
  1358. ~~ASC
  1359. ASC(character/string )
  1360.     ASCII code of a character/string.
  1361. Note:    Conversion from internal code(s) of a character/string
  1362.     to a value.
  1363.     It is the same as in BASIC if the argument is one
  1364.     character.
  1365. Out:    integer.
  1366. Ex:    print asc("A")    result: 65
  1367. See:    CHR.
  1368.  
  1369. ~~ATAN
  1370. ATAN(x)
  1371.     Arctangent of x.
  1372.     If x is real, the value is larger than -pi/2 and less than
  1373.     or equal to pi/2.
  1374. Out:    real, complex number.
  1375. Ex:    print atan(1)    result: 0.7853...
  1376. See:    appendix B for the algorithm.
  1377.  
  1378. ~~ATTRIB
  1379. ATTRIB(x)
  1380.     Attribute word of x.
  1381. Note:    In ordinary cases, TYPE is recommended.
  1382. Inp:    any data.
  1383. Out:    string (hexadecimal conversion of the
  1384.     attribute word).
  1385. See:    TYPE.
  1386.  
  1387. ~~AUTO
  1388. AUTO [start_line_number]
  1389.     Generates line numbers.
  1390. Note:    Starts from largest_line_number+10 if no line number is
  1391.     given.
  1392.  
  1393. ~~BEEP
  1394. BEEP
  1395.     Rings the bell.
  1396.  
  1397. ~~BESSELI
  1398. BESSELI(k,x)
  1399.     k-th Bessel_I function of x.
  1400. Inp:    k is an integer larger than 0. x is a number.
  1401. Out:    number.
  1402. Ex:    print besseli(1,2.3)    result: 2.0978...
  1403. See:    appendix B for the algorithm.
  1404.  
  1405. ~~BESSELJ
  1406. BESSELJ(k,x)
  1407.     k-th Bessel_J function of x.
  1408. Inp:    k is an integer larger than 0. x is a number.
  1409. Out:    number.
  1410. Ex:    print besselj(1,2.3)    result: 0.5398...
  1411. See:    appendix B for the algorithm.
  1412.  
  1413. ~~BIT
  1414. BIT(n,x)
  1415.     n-th bit of x.
  1416. Inp:    n is an integer. x is any data.
  1417. Out:    integer (0 or 1).
  1418. Ex:    BIT(0, 5) = 1, BIT(1, 5) = 0, BIT(2, 5) = 1,
  1419.     BIT(3, 5) = 0.
  1420. Note:    Result has almost no meaning when x is a decimal.
  1421. See:    LEN.
  1422.  
  1423. ~~BLOAD
  1424. BLOAD "machine_language_program", short_var([arg1, arg2, ...])
  1425. See:    the "User Programs" section.
  1426.     Arguments must be simple variables.
  1427.  
  1428. ~~BLOCK
  1429. BLOCK array(index,index...)
  1430.     Assigns values to the specified array members.
  1431. Ex:    block A(2..4, 3..6) = X
  1432.         assigns X to each A(i, j) for i=2,3,4 and j= 3,4,5,6.
  1433.  
  1434.     block A(*,*) = X
  1435.         assigns X to all the elements.
  1436.  
  1437.     block B(0..2) = block A(2, 1..3)
  1438.         assigns A(2, 1) to B(0), etc.
  1439.  
  1440.     swap block B(0..2), block A(2, 1..3)
  1441.         swaps the values.
  1442.  
  1443.         Note that a double exchange occurs when overlapping parts
  1444.         of one array are specified. In this case, results are 
  1445.         unpredictable.
  1446.  
  1447.     clr block A(2..3,4..5)
  1448.         sets to zero (same as block A(2..3,4..5)=0).
  1449.  
  1450.     neg block B%(0..5)
  1451.         changes signs.
  1452.  
  1453.     You can also use expressions such as
  1454.  
  1455.     block A(2..4) += expression
  1456.     block A(2..4) += block B(3..5)
  1457.  
  1458.     and these with + replaced by -, *, /, \, and @.
  1459.     The first of these is the same as
  1460.     A(2)=A(2)+(expression):A(3)=A(3)+(expression)
  1461.     :A(4)=A(4)+(expression)
  1462.     Note the parenthesis in the right hand side.
  1463.     In the second, you cannot add any term to the right hand
  1464.     side.
  1465.  
  1466. Note:    When a user-defined function is called in the middle of
  1467.     the calculation of an index or an expression, BLOCK
  1468.     used in this function creates an error.
  1469.     When BLOCK is used on both sides of an expression, the
  1470.     number of the indices must be the same though the
  1471.     composition may vary.
  1472.  
  1473. See:    CLR, NEG, SWAP.
  1474.  
  1475. ~~CALL
  1476. CALL short_array_name([arg1,arg2,...])
  1477.     Calls a user machine language program after the arguments
  1478.     are set.
  1479. See:    the "User Programs" section.
  1480.  
  1481. ~~CANCEL
  1482. CANCEL for<,for,for,...>
  1483.     Cancels the current for-next loop before jumping out of it.
  1484. Ex:    cancel for
  1485. Note:    Use GOTO to specify where to jump.
  1486.     GOTO is necessary, unlike 'break' or 'cancel' statements
  1487.     in other languages.
  1488. See:    FOR.
  1489.  
  1490. ~~CHR
  1491. CHR(ASCII code)
  1492. Inp:    integer. Signs are neglected.
  1493. Out:    character/string.
  1494. Ex:    print chr(65)    result:A
  1495. See:    ASC.
  1496. Note:    The format of hexadecimal expression is not '&h..' but
  1497.     '0x..'.
  1498.  
  1499. ~~CLOSE
  1500. CLOSE
  1501. CLOSE [#n]
  1502. CLOSE file1[,file2,...]
  1503.     Closes the open files.  If no file name (or file number) is
  1504.     given, then it closes all the open files.
  1505. See:    EOF, OPEN.
  1506.  
  1507. ~~CLR
  1508. CLR variable1[,variable2,...]
  1509.     Sets the variables to zero.  "CLR A" is faster than "A = 0".
  1510. Ex:    clr A,B,C
  1511.         sets A, B, C to 0.
  1512. See:    DEC, INC, NEG.
  1513.  
  1514. CLR BLOCK arrayname(index)
  1515.     Sets the specified members of an array to 0.
  1516. Ex:    clr block A(0..10)
  1517.         sets from A(0) to A(10) to 0.
  1518.     clr block A(2,1..3)
  1519.         sets A(2,1),A(2,2),A(2,3) to 0.
  1520. See:    BLOCK for details.
  1521.  
  1522. CLR TIME
  1523.     Sets the clock to "00:00:00".  Effective only inside UBASIC.
  1524.     It does not initialize the system clock, so there may be an
  1525.     error of up to one second.
  1526.  
  1527. ~~CLS
  1528. CLS [n]
  1529.     Clears the screen.
  1530. Inp:    none or integer 1.
  1531. Note:    Clears the text screen.
  1532. Ex:    10    console 0,25:cls
  1533.  
  1534. ~~CCOEFF
  1535. CCOEFF(polynomial)
  1536.     Constant term of polynomial.
  1537. Ex:    A=poly(1,3,5):print ccoeff(A)    result: 1
  1538. See:    COEFF, LCOEFF.
  1539.  
  1540. ~~COEFF
  1541. COEFF(polynomial,degree)
  1542.     Coefficient of the term of specified degree of polynomial.
  1543. COEFF(polynomial, degree)=expression
  1544.     Assigns a value to the coefficient of the term of specified
  1545.     degree of polynomial.
  1546. Inp:    argument1 is a polynomial or 0.
  1547.     argument2 is an integer (>= 0).
  1548. Ex:    A=poly(1,3,5):print coeff(A,2)    result: 3
  1549.     A=0:coeff(A,3)=2:coeff(A,0)=5:print A    result: 2*X^3 + 5.
  1550. See:    CCOEFF, LCOEFF, POLY.
  1551.  
  1552. ~~COLOR
  1553. COLOR(n)
  1554.     Specifies text color. (0 =< n =< 7)
  1555.  
  1556. ~~COMBI
  1557. COMBI(n,r)
  1558.     Number of combinations extracting r elements from n elements.
  1559. Inp:    integer n (0 <= n < 65536).
  1560. Out:    integer.
  1561. Ex:    print combi(4,2)    result: 6
  1562.  
  1563. ~~CONJ
  1564. CONJ(x)
  1565.     Complex conjugate of x.
  1566. Inp:    number.
  1567. Out:    number.
  1568. Ex:    print conj(1+2#i)    result: 1-2#i
  1569. See:    IM, RE.
  1570.  
  1571. ~~CONT
  1572. CONT
  1573. See:    STOP.
  1574.  
  1575. ~~CONSOLE
  1576. CONSOLE start line,lines in console area[, function key display
  1577.     switch(0/1)]
  1578.     Declares the console window area.
  1579. Note:    When the second argument is '*',the number of lines is
  1580.     set to the maximum.
  1581.     Settings are initialized when no argument is given.
  1582. Inp:    Start_line is from 0 to 24.
  1583.     Lines_in_console_area is from 5 to 25.
  1584.     Function_key_display_switch is 1 (displays) or 0
  1585.     (not displays).
  1586. Ex:    console 0,20,0
  1587.         sets the console area to 20 lines starting from
  1588.     line 0 (to line 19), and displays no function keys.
  1589.  
  1590. ~~COS
  1591. COS(x)
  1592.     Cosine of x.
  1593. Inp:    number.
  1594. Out:    number.
  1595. Ex:    print cos(1.23)    result: 0.3342...
  1596. See:    SIN,TAN
  1597.     Appendix B for the algorithm.
  1598.  
  1599. ~~COSH
  1600. COSH(x)
  1601.     Hyperbolic cosine of x.
  1602. Note:    (exp(x)+exp(-x))/2
  1603. Inp:    number.
  1604. Out:    number.
  1605. Ex:    print cosh(1.23)    result: 1.8567...
  1606. See:    SINH.
  1607.     appendix B for the algorithm.
  1608.  
  1609. ~~CUTLSPC
  1610. CUTLSPC(string)
  1611.     Cuts off the spaces in the left end of a string.
  1612. Inp:    string.
  1613. Out:    string.
  1614. Ex:    print "A":cutlspc("    B C")    result:AB C
  1615.  
  1616. ~~CUTSPC
  1617. CUTSPC(string)
  1618.     Cuts off all the spaces in a string.
  1619. Inp:    string.
  1620. Out:    string.
  1621. Ex:    print "A":cutspc("    B C")    result:ABC
  1622.  
  1623. ~~CVR
  1624. CVR(x)
  1625.     Decimal expression of the numerator of rational divided by
  1626.     the denominator.
  1627. Inp:    integer, decimal, rational.
  1628. Out:    real.  argument ifself if it is not rational.
  1629. Ex:    print cvr(1//3)    result: 0.3333...
  1630.  
  1631. ~~DATA
  1632. DATA expression1[,expression2,...]
  1633.     Data for READ statements.
  1634. Note:    A string must be put in " ".
  1635.     Commands placed after DATA in the same line are
  1636.     neglected.
  1637. See:    READ, RESTORE.
  1638.  
  1639. ~~DATE
  1640. DATE
  1641.     String containing current date and time.
  1642. Ex:    print date
  1643.         displays current year, month, day, hour, minute and
  1644.         second.
  1645. Out:    string.
  1646. Note:    CLR TIME does not affect the time represented by DATE.
  1647.  
  1648. ~~DEC
  1649. DEC variable1[,variable2,...]
  1650.     Decrements the variables.  "DEC A" is faster than
  1651.     "A = A - 1."
  1652.     The variable must currently hold integer values.
  1653. Ex:    A=100:dec A:print A    result: 99
  1654. See:    CLR, INC, NEG.
  1655.  
  1656. ~~DECODE
  1657. DECODE(ENCODEd_string)
  1658.     Original string of an ENCODEd string.  Tokens are marked
  1659.     off by a space.
  1660. Ex:    print decode(encode("x+sin(abc)")    result: X + sin( Abc )
  1661. See:    ENCODE.
  1662.  
  1663. ~~DEFSEG
  1664. DEFSEG = segment
  1665.     Specifies the segment to be accessed by PEEK and POKE.
  1666. Note:     Do not put a space between DEF and SEG.
  1667. See:    PEEK, PEEKW, PEEKS, POKE, POKEW, POKES, VARPTR.
  1668.  
  1669. ~~DEG
  1670. DEG(polynomial)
  1671.     Degree of polynomial.
  1672. Note:    Degree of 0 is defined to be -1.
  1673. Ex:    A=poly(0,0,1):print deg(A)    result: 2
  1674. See:    LEN.
  1675.  
  1676. ~~DELETE
  1677. DELETE linenumber1 - linenumber2
  1678.     Deletes the portion of the program.
  1679.  
  1680. ~~DEN
  1681. DEN(rational)
  1682.     Denominator of the argument.
  1683. Inp:    integer, rational.
  1684. Ex:    print den(2//3)    result: 3
  1685. See:    NUM.
  1686.  
  1687. ~~DIFF
  1688. DIFF(polynomial)
  1689.     Differential of polynomial.
  1690. Ex:    A=poly(1,1,1):print diff(A)    result: 2*X + 1
  1691.  
  1692. ~~DIM
  1693. DIM arrayname(bound1[,bound2[,bound3]])
  1694.     Declares arrays, specifies the number of indices and sets
  1695.     all the members of the arrays to 0.
  1696. Note:    The indices start at 0.
  1697.     The bounds are nonnegative integers such that
  1698.     bound1 <= 65534,  (bound2 + 1) * (bound3 + 1) <= 65535.
  1699.  
  1700.     In subroutines and functions, declarations of arrays
  1701.     must be placed at the beginning, not in the middle.
  1702.     The arrays declared in a subroutine or function are
  1703.     valid only in that subroutine or function and is are
  1704.     erased by RETURN.
  1705.  
  1706.     EMA-arrays are NOT automatically erased by RUN.  So it is
  1707.     recommended to place EMAWORD just before DIM EMA().
  1708. See:    ERASE.
  1709.  
  1710. ~~DIR
  1711. DIR ["pathname"]
  1712.     Displays the names of the programs on a disk.
  1713.     The path can contain wildcard match characters.
  1714. Ex:    dir "a:\bin\a*.*"
  1715.         displays the file names beginning with 'a' in the
  1716.     \bin directory of drive A.
  1717.  
  1718.     Note the following symbols:
  1719.     +    data file
  1720.     *    machine-language program
  1721.     p    write protected
  1722.     Sizes are given in 100 bytes.
  1723.  
  1724. DIR="path"
  1725.     Changes the current directory.
  1726. Ex:    dir="b:"
  1727.         Changes the object of LOAD and SAVE to drive B.
  1728. Note:    Do not put '\' at the end of path name.
  1729.  
  1730. DIR
  1731.     gives the current drive name and directory name.
  1732. Inp:    nothing.
  1733. Out    string.
  1734. Ex:    DirMemo=dir:dir="b:":do something:dir=DirMemo
  1735.             return to the current directory after moving to some 
  1736.             other directory.
  1737.  
  1738. ~~DOSCMD
  1739. DOSCMD string
  1740.     Invokes the command.com file to execute a DOS command.
  1741. Ex:    DOSCMD "dir b:"
  1742.         temporally transfers control to MS-DOS to execute
  1743.     'dir b:'.  But the display is cleard at once and
  1744.     control is returned to UBASIC.
  1745.     In this case, it is recommended that command.com is
  1746.     re-invoked by DOSCMD "a:\command".
  1747.     DOSCMD "program name" runs the specified program.
  1748. Note:    A program using graphic areas may destroy the work area
  1749.     of UBASIC.
  1750.     You may destroy the screen #1 of graphic RAM.
  1751.  
  1752. ~~EDIT
  1753. EDIT [line_number or label]
  1754.     Displays a screenful of the current program including the
  1755.     specified line.
  1756.     The default line is the previously specified or edited
  1757.     line, or the line on which the most recent error occurred.
  1758.  
  1759. ~~ELSE
  1760. ELSE
  1761. See:    IF.
  1762.  
  1763. ~~ELSEIF
  1764. ELSEIF
  1765. See:    IF.
  1766. Note:    Do not put a space between ELSE and IF.
  1767.  
  1768. ~~EMA
  1769. EMA([expanded_array_number];index1,index2)
  1770.     Specified member of an EMA-array.
  1771. Ex:    print ema(1;2,3)
  1772.         displays the member(2,3) of EMA #1.
  1773. See:    EMA-array.
  1774.  
  1775. ~~EMAWORD
  1776. EMAWORD expression
  1777.     Specifies the size of a member of an EMA-array.
  1778. Note:    Do not put a space between EMA and WORD.
  1779. See:    EMA-array.
  1780.  
  1781. ~~ENCODE
  1782. ENCODE(string)
  1783.     Converts a string containing an expression or command to
  1784.     internal codes.
  1785. Note:    This makes VAL faster.
  1786. See:    VAL, DECODE.
  1787.  
  1788. ~~END
  1789. END
  1790.     Closes all files and ends program execution,
  1791.     sends a newline character to the printer if necessary,
  1792.     and cancels unterminated loops.
  1793.  
  1794. ~~ENDIF
  1795. ENDIF
  1796. See:    IF.
  1797. Note:    Do not put a space between END and IF.
  1798.  
  1799. ~~ENDLOOP
  1800. ENDLOOP
  1801. See:    LOOP.
  1802. Note:    Do not put a space between END and LOOP.
  1803.  
  1804. ~~EOF
  1805. EOF(n)
  1806.     1 if the content of file #n is exhausted, 0 otherwise.
  1807. Inp:    integer.
  1808. Out:    integer (0 or 1).
  1809. Ex:    10    open "abc" for input as #1
  1810.     20    while not eof(1)
  1811.     30      input #1,a
  1812.     40      print a
  1813.     50    wend
  1814.     60    close
  1815.         Continues to read until the data are exhausted.
  1816.     If EOF is not checked, an error occurs when the data
  1817.     are exhausted.
  1818.  
  1819. ~~ERASE
  1820. ERASE array1 [,array2,... ]
  1821.     Erases arrays.  Array names must be followed by parentheses, 
  1822.     e.g. "erase a()".  If the arrays a(m) and b(n) are 
  1823.     DIMensioned in this order, then it is faster to erase b(), 
  1824.     then a().  ERASE should not be used in subroutines and 
  1825.     functions.  Arrays created in subroutines and functions are 
  1826.     erased automatically by RETURN.
  1827. See:    DIM.
  1828.  
  1829. ~~ERROR
  1830. ERROR GOTO [line_number or label]
  1831. Note:    Usually, a program stops if an error occurs.  However,
  1832.     if a routine to handle errors has been specified by
  1833.     ON ERROR GOTO, the execution proceeds to that routine.
  1834. Ex:    10    on error goto *ErrorTrap
  1835.     20    print 1/0
  1836.     30    end
  1837.     40    *ErrorTrap
  1838.     50    print "error"
  1839.     60    end
  1840.         A "division by zero" error occurs in line 20.  Then the
  1841.     execution continues from line 40 as specified in line 10.
  1842. Note:    This statement does not work well. There is no "resume
  1843.     statement".  And this clears all the work areas
  1844.     concerning control of execution, so a program will not
  1845.     be executed normally if the error handling routine is
  1846.     designed to jump back to the subroutine where error has
  1847.     occurred.  This statement is recommendded only in
  1848.     programs which have a main menu and branches out of it.
  1849. See:    GOTO.
  1850.  
  1851. ~~EUL
  1852. EUL(n)
  1853.     Euler's function of n.
  1854. Inp:    integer n (1 <= n <= 4294967295).
  1855. Out:    integer.
  1856. Ex:    print eul(100)    result: 40
  1857.  
  1858. ~~EVAL
  1859. EVAL(string)
  1860.     Interprets a string as a command and executes it.
  1861. Note:    It is recommended to ENCODE the string if you want to
  1862.         evaluate it often.
  1863. Ex:    eval("list "+str(x))
  1864.         lists the lines specified by x.
  1865. See:    VAL.
  1866.  
  1867. ~~EVEN
  1868. EVEN(n)
  1869.     1 if n is even, 0 if odd.
  1870. Ex:    print even(10),even(11)    result: 1    0
  1871. See:    ODD.
  1872.  
  1873. ~~EXIST
  1874. EXIST("filename")
  1875.     1 if the file specified by "filename" exists, 0 otherwise.
  1876. Out:    integer (0 or 1).
  1877. Note:    An error occurs if you try to OPEN a file which does
  1878.     not exist.  The purpose of  the EXIST function is to
  1879.     avoid that error.
  1880. Note:    Extension of filename cannot be ommited.
  1881. Ex:    if exist("abc.ubd") then open "abc" for input as #1
  1882.  
  1883. ~~EXP
  1884. EXP(x)
  1885.     e to the x.  
  1886. Ex:    print exp(1.23)    result: 3.4212...
  1887. See:    Appendix B for the algorithm.
  1888.  
  1889. ~~FACTORIAL
  1890. FACTORIAL(n)
  1891.     Factorial of n.
  1892. Inp:    integer n (0 <= n <= 1014).
  1893. Out:    integer.
  1894. Ex:    print factorial(12)    result: 479001600
  1895.  
  1896. ~~FILE
  1897. FILE
  1898. See:    OPEN.
  1899.  
  1900. ~~FILE1
  1901. FILE1(n), FILE2(n), FILE3(n)
  1902.     Random files declared by OPEN statements.
  1903.     Special elements:
  1904.     FILEi(-1) = number of elements
  1905.     FILEi(-2) = element word size
  1906.     FILEi(-3) = POINT WORD length
  1907. See:    Random files.
  1908.  
  1909. ~~FILE2
  1910. FILE2
  1911. See:    FILE1
  1912.  
  1913.  
  1914. ~~FILE3
  1915. FILE3
  1916. See:    FILE1
  1917.  
  1918.  
  1919. ~~FIND
  1920. FIND(x,a(i),n)
  1921.     (Index - i) of the first occurrence of x in  a(i), ...,
  1922.     a(i+n-1).
  1923.     A negative value is returned if none is equal to x.  The
  1924.     array must be sorted in ascending or descending order.
  1925.     Binary search is used.
  1926. Inp:    x and a(i) are integer or real. n is an integer.
  1927. Out:    integer.
  1928. Ex:    find(3,A(2),10)
  1929.         if the return value is 4, a(6) is 3 (not a(4)).
  1930.  
  1931. ~~FIX
  1932. FIX(x)
  1933.     Integer part of x, truncating towards zero.
  1934. Inp:    integer, real, rational.
  1935. Out:    integer.
  1936. Note:    The result may differ from that of INT(x) when x is
  1937.     negative.
  1938. Ex:    print fix(12345/100)     result: 123
  1939.     print fix(-12345/100)    result:-123
  1940. See:    INT, ROUND.
  1941.  
  1942. ~~FN
  1943. FN function name (arg1, arg2, ...)
  1944.     Begins a user-defined function name.
  1945. Ex:    100    a=fnMAX(A,B)            'Calls function
  1946.     ...
  1947.     200    fnMAX(X,Y)            'Declaration of
  1948.                         function
  1949.     210      local Z            'Definition of a
  1950.                         local variable
  1951.     220      if X>=Y then Z=X else Z=Y
  1952.     230    return(Z)            'Returns a value
  1953. Note:    You may type '.' for 'fn'.
  1954. See:    "Subroutines and Functions" for details.
  1955.  
  1956. ~~FOR
  1957. FOR variable = initial_value TO final_value [STEP increment]
  1958. NEXT [variable]
  1959.     All the values must be integers.  The number of iterations
  1960.     is determined at the beginning of the loop as
  1961.  
  1962.     (final_value - initial_value) \ increment + 1
  1963.  
  1964.     which may not exceed 4294967295.  If it is zero or negative,
  1965.     the loop is not executed.
  1966.     The loop cannot be terminated by changing the value of the
  1967.     loop variable in it.  When the loop is terminated normally,
  1968.     the value of the loop variable is
  1969.     initial_value+number_of_iterations*increment.
  1970.     To jump out of the for-next loop, use CANCEL FOR.
  1971. Ex:    10    S=0
  1972.     20    for I=1 to 100
  1973.     30      S=S+I:if S>100 then cancel for:goto 50
  1974.     40    next I
  1975.     50    print I;S
  1976.     60    end
  1977.  
  1978. ~~FREE
  1979. FREE
  1980.     Displays the size of the available program area and stack
  1981.     area.
  1982. Note:    The available text area (=program area) shows how many
  1983.     more bytes of program codes you may write.
  1984.     The available stack area shows how many words in the
  1985.     256 words of system stack have never been used (not
  1986.     "are not being used now").  This is to monitor the
  1987.     system and can usually be ignored.
  1988.  
  1989. ~~FREEZE
  1990. FREEZE ["filename"]
  1991.     Writes the current program, variables, and other
  1992.     information on to a disk.  If you HALT and FREEZE the
  1993.     program execution, you can MELT and CONTinue it later.
  1994.     The size of the frozen file is 100k-300k bytes.
  1995. Note:    You can MELT the frozen information.  The filename should
  1996.     not contain an extension since ".ice" is automatically
  1997.     added.  "UB.ICE" in the current drive is used if the
  1998.     filename is not given.
  1999.     The disk must have 200k-500k bytes of free area.  The
  2000.     latter half of UBASIC and variable areas are frozen.
  2001.     FREEZE does not save the area of memory used by a
  2002.     machine-language program that is not in a UBASIC array.
  2003.     MELT does not work if the arrangement of memory has
  2004.     been changed.  This occurs when CONFIG.SYS is modified
  2005.     or memory resident programs are loaded.
  2006.  
  2007.     In ordinary BASIC, when you want to do another job
  2008.     while running a program which takes a lot of time, you
  2009.     have no choice but to abort the running program or to
  2010.     give up the new job.  There is no satisfactory solution
  2011.     as DOS does not currently support multi-tasking.
  2012.     However, to FREEZE the running program is an effective
  2013.     solution.
  2014. Ex:    1) Stop the running program by ctrl+BREAK or ctrl+c.
  2015.     2) FREEZE the current status of memory on to a disk.
  2016.     3) Start and finish another job.
  2017.     4) MELT the frozen memory.
  2018.     5) Continue the program by CONT.
  2019.  
  2020. See:    MELT.
  2021.  
  2022. ~~GCD
  2023. GCD(m,n)
  2024.     Greatest common divisor of m and n.
  2025. Inp:    integer, rational polynomial or modulo polynomial.
  2026. Out:    integer(>=0), rational polynomial or monic modulo polynomial.
  2027. Ex:    print gcd(49,63)    result: 7
  2028.     print gcd(_x^2-1, _x^2+2*_x+1)    result: 2*x + 2
  2029.  
  2030. ~~GETENV
  2031. GETENV("environment variable name")
  2032.     contents of environment variables.
  2033. Inp:    string.
  2034. Out:    string, 0 if no such name exxists.
  2035.  
  2036. ~~GOSUB
  2037. GOSUB line_number or label
  2038.     Calls the subroutine.
  2039. GOSUB label(parameter1,parameter2,...)
  2040.     Calls the subroutine with parameters.
  2041. Note:    The subroutine called must have the same format of
  2042.     arguments.
  2043.     If an argument is a variable or an expression, the
  2044.     current value of it is assigned to the corresponding
  2045.     variable.  The previous value of the variable is pushed
  2046.     on to the stack and restored by the corresponding
  2047.     RETURN.
  2048.     Variables can be passed by address (use &).
  2049.     The corresponding variables share the same memory area.
  2050.     Array names must be followed by "()".
  2051.  
  2052. Ex:    10    A=1:B=2:C=0
  2053.     20    gosub *MAX(A,B,&C)    :'A,B are passed by value
  2054.     30    print C            :'&C is passed by address
  2055.     40    end            :'thus in *MAX, Z is
  2056.                      identified with C
  2057.     100    *MAX(X,Y,&Z)        :'X and Y are local variables
  2058.                      in *MAX
  2059.     110      if X>=Y then Z=X else Z=Y  :'they do not change X
  2060.                     and Y in the
  2061.     120    return            :'main routine if valiables
  2062.                      of the same name exist.
  2063. Note:    A simple short variable cannot be passed by address,
  2064.     i.e.  gosub *ABC(&A%) is not allowed.
  2065.     An array can be passed by address,
  2066.     i.e.  gosub *ABC(&A()) is allowed,
  2067.     but a member of an array cannot be passed by address,
  2068.     i.e.  gosub *ABC(&A(1)) is not allowed.
  2069.     An array can be passed by value also.
  2070.     i.e. gosub *ABC(A()) passes all the members by value.
  2071.  
  2072. ~~GOTO
  2073. GOTO line_number or label
  2074.     Goes to the specified line.
  2075.  
  2076. ~~HEX
  2077. HEX(n)
  2078.     Hexadecimal conversion of n.
  2079. Note:    Converts the internal expresson of n to a string. If
  2080.     n is an integer or a decimal, the string begins with
  2081.     highest byte. Otherwise, it begins with lowest byte.
  2082.     Take care with rationals and complex numbers, since one
  2083.     byte has 2 digits and there is no separator between
  2084.     bytes.
  2085. Ex:    print hex(65534)    result:fffe
  2086.     print hex("abc")    result:616263
  2087. Note:    The format of a hexadecimal expression is not '&h..'
  2088.     but '0x..'.
  2089.  
  2090. ~~IF
  2091. IF
  2092.     1)IF expression THEN statements [ENDIF]
  2093.     If the value of the expression is not zero, then the
  2094.     statements after THEN are executed.
  2095.  
  2096.     2)IF expression THEN statements ELSE statements [ENDIF]
  2097.     If the value of the expression is not zero, then the
  2098.     statements after THEN are executed; otherwise the
  2099.     statements after ELSE are executed.
  2100.  
  2101.     3)IF expression THEN statements ELSEIF expression THEN
  2102.     statements  ELSEIF ...    ... ELSE statements [ENDIF]
  2103.     This form is used for multiple branching.
  2104.     The expressions are evaluated in order and the
  2105.     statements after THEN after the first nonzero
  2106.     expression are executed.
  2107.     When all the expressions are zero, the statements after
  2108.     ELSE are executed.
  2109.  
  2110. Note:    ENDIF may be omitted if the next line is not
  2111.     a continuation.  ELSE and ENDIF correspond to the
  2112.     nearest IF before them.
  2113.     A ":" between statements can be omitted before and after
  2114.     IF, THEN, ELSEIF, ELSE, and ENDIF.
  2115.  
  2116.     Continuation of a line:
  2117.     The statements can be written in multiple lines.
  2118.     A line beginning with a colon (:) is a continuation of
  2119.     the previous line.
  2120.  
  2121.     Thus, the program portion
  2122.  
  2123.         10    if A<>1 then *ABC
  2124.         20    B=1:BB=10
  2125.         30    C=11:CC=110
  2126.         40    *ABC
  2127.  
  2128.     is equivalent to
  2129.  
  2130.         10    if A=1 then
  2131.         20      :B=1:BB=10
  2132.         30      :C=11:CC=110
  2133.  
  2134.     Note that statements after REM (or ' ) may be regarded
  2135.     differently.  In the following line, "B=1" is not
  2136.     executed as it is regarded as a comment:
  2137.         10    A=1:'TEST:B=1
  2138.  
  2139.     But in the following lines, "B=1" is executed:
  2140.         10    A=1:'TEST
  2141.         20    :B=1
  2142.  
  2143.     The ENDIF in
  2144.  
  2145.         10    if A then B else C: D endif
  2146.  
  2147.     may be omitted, but not in
  2148.  
  2149.         10    if A then B else C endif D
  2150.  
  2151.     which is equivalent to
  2152.  
  2153.         10    if A then B else C
  2154.         20    D
  2155.  
  2156.     "If then else" may be nested.  The line
  2157.  
  2158.         10    if A then if D then E else F: C
  2159.  
  2160.     is equivalent to
  2161.  
  2162.         10    if A then
  2163.         20    :if D then E else F
  2164.         30    :C
  2165.  
  2166.     whereas the line
  2167.  
  2168.         10    if A then if D then E else F endif C
  2169.  
  2170.     is equivalent to
  2171.  
  2172.         10    if A then
  2173.         20    :if D then E else F endif
  2174.         30    :C
  2175.  
  2176.     Multiple IF:
  2177.         10    if A then B:C
  2178.     If you want to replace B by the construction "if D then
  2179.     E else F", do not simply insert it thus:
  2180.         10    if A then if D then E else F:C
  2181.     because C would then be regarded as a continuation of
  2182.     the ELSE statement F and would be executed only when A
  2183.     is nonzero and D is zero.    So in this example ENDIF,
  2184.     which was omitted in the original line, must be
  2185.     restored in this way:-
  2186.  
  2187.         10    if A then if D then E else F endif C
  2188.  
  2189.     The line continuation (:) makes the above complicated
  2190.     line plain:
  2191.  
  2192.         10    if A then
  2193.         20    :if D then E else F endif
  2194.         30    :C
  2195.  
  2196.     The following lines have a different meaning, as
  2197.     mentioned above:
  2198.  
  2199.         10    if A then
  2200.         20    :if D then E else F
  2201.         30    :C
  2202.  
  2203.     Multiple branching:
  2204.     Multiple branching is realized by continuation of lines
  2205.     and ELSEIF.
  2206.  
  2207.         10    input A
  2208.         20    if A<=10 then print 1
  2209.         30    :elseif A<=20 then print 2
  2210.         40    :elseif A<=30 then print 3
  2211.         50    :elseif A<=40 then print 4
  2212.         60    :else print 5
  2213.  
  2214.     displays 1, 2, 3, 4 when A<=10, 10<A<=20, 20<A<=30,
  2215.     30<A<=40 respectively. It displays 5 otherwise.
  2216.  
  2217.     Note the following case in which another IF is used in
  2218.     a branch.
  2219.  
  2220.     If "print 2" in the above list is replaced by
  2221.     "if A=25 then print 2.5 else print 2", line 30 becomes
  2222.     like this:
  2223.  
  2224.         30    :elseif A<=20 then if A=25 then print 2.5
  2225.             else print 2 endif
  2226.  
  2227.     Note that ENDIF must not be omitted.  IF - ENDIF should
  2228.     be regarded as one block separate from other IF
  2229.     statements.
  2230.  
  2231.     However it may be proper to arrange it like this:
  2232.  
  2233.         30    :elseif A<=20 then
  2234.         35    :if A=25 then print 2.5 else print 2 endif
  2235.  
  2236.     or like this:
  2237.  
  2238.         30    :elseif A<=20 then
  2239.         32    :if A=25 then print 2.5
  2240.         34    :else print 2
  2241.         36    :endif
  2242.  
  2243.     The difference between ELSEIF and ELSE IF:
  2244.  
  2245.         if a=1 then x=80 elseif a=2 then x=90 else x=100
  2246.  
  2247.     is equivalent to
  2248.  
  2249.         if a=1 then x=80 else if a=2 then x=90 else x=100
  2250.  
  2251.     But when ENDIF is needed in relation to another IF
  2252.     statement, a difference of structure appears.
  2253.  
  2254.     In the first case, you just add it at the end:
  2255.  
  2256.         if a=1 then x=80 elseif a=2 then x=90 else x=100
  2257.         endif
  2258.  
  2259.     In the second case, as there are two statements put
  2260.     together, ENDIF is needed for each of the statement:
  2261.  
  2262.         if a=1 then x=80 else if a=2 then x=90 else x=100
  2263.         endif endif
  2264.  
  2265.     ELSE can end an IF statement.  For example:
  2266.  
  2267.         if A then if B then C else D else E
  2268.  
  2269.     In this case, the "if B" statement ends before
  2270.     "else E".
  2271.  
  2272.     The use of ENDIF as in the following line is
  2273.     preferable:
  2274.  
  2275.         if A then if B then C else D endif else E
  2276.  
  2277. ~~IM
  2278. IM(x)
  2279.     Imaginary part of x.
  2280. Inp:    number.
  2281. Out:    number.
  2282. Ex:    print im(123+456#i)    result: 456
  2283. See:    CONJ, RE.
  2284.  
  2285. ~~INC
  2286. INC variable1 [,variable2,... ]
  2287.     Increments the variables.  "INC A" is faster than "A = A + 1".
  2288.     The current value of the variable must be an integer.
  2289. Ex:    A=100:inc A:print A    result: 101
  2290. See:    CLR, DEC, NEG.
  2291.  
  2292. ~~INKEY
  2293. INKEY
  2294.     Checks keyboard buffer.
  2295. Note:    Character in the keyboard buffer if there is any, null
  2296.     string otherwise.
  2297. Out:    character.
  2298. Ex:    10    while not inkey
  2299.     20      gosub 100
  2300.     30    wend
  2301.         repeats the subroutine beginning at line 100 until
  2302.     any key is pressed.
  2303.  
  2304. ~~INP
  2305. INP(port#)
  2306.     Inputs from the input port specified by port#.
  2307. Inp:    integer.
  2308. Out:    integer.
  2309. See:    OUT.
  2310.  
  2311. ~~INPUT
  2312. INPUT
  2313. 1) INPUT ["prompt";] variable1 [, variable2, ... ]
  2314.     Waits for a number or an expression and assigns its
  2315.     value to the variable.  If more than one variable is
  2316.     specified, separate the input numbers/expressions by
  2317.     commas.
  2318. Note:    UBASIC looks for the first "?" on the cursor line
  2319.     and takes everything after it as input.  UBASIC
  2320.     supplies a prompting "?", so do not include one in
  2321.     your "prompt".  You can input anything on screen by
  2322.     moving the cursor to it and preceding it by a "?".
  2323.     Input is passed through the UBASIC interpreter, so
  2324.     it can include formulae and variable names.
  2325. Ex:    10    input "Enter a number:";A
  2326.     20    print A
  2327. See:    STRINPUT.
  2328.  
  2329. 2) INPUT = "filename"
  2330.     Redirects the input to the specified ASCII file.
  2331.     Characters other than numerals and periods are
  2332.     interpreted as delimiters.
  2333.     INPUT = INPUT cancels the redirection.
  2334. See:    STRINPUT.
  2335.  
  2336. 3) open "filename" for INPUT as #n
  2337. See:    OPEN.
  2338.  
  2339. ~~INPUT$
  2340. INPUT$(n)
  2341.     Waits for n keystrokes, then returns them as a string.
  2342. Note:    If n > 0 , the cursor is displayed.
  2343.     If n < 0 , the cursor is not displayed.
  2344. Inp:    integer.
  2345. Out:    string.
  2346. Ex:    10    A=input$(-1)
  2347.         waits for a keystroke without displaying the cursor.
  2348. Note:    Note that "$" is needed, unlike other string functions
  2349.     in UBASIC.
  2350.     This function repeats the function 0ch(7) of MS-DOS
  2351.     INT21H.
  2352.  
  2353. ~~INPUT #
  2354. INPUT #n, var1 [,var2,...]
  2355.     Reads the  value(s) of the variable(s) from file #n (n = 1
  2356.     , 2, ...).
  2357. Note:    Multiple values can be read with one INPUT # statement.
  2358.     Variables must be marked off with ",".
  2359. See:    CLOSE, EOF, OPEN.
  2360.  
  2361. ~~INSTR
  2362. INSTR([n],string1,string2)
  2363.     Scans string1 starting from n-th character of string1 for
  2364.     the occurence of string2 and returns the location of the
  2365.     first character of string2.
  2366.     Returns 0 if string2 does not occur.
  2367. Inp:    n is an integer.
  2368. Out:    integer.
  2369. Ex:    print instr("abcbcacab","ca")    result: 5
  2370. See:    INSTR2.
  2371.  
  2372. ~~INSTR2
  2373. INSTR2([n],string1,string2)
  2374.     Scans string1 starting from n-th character of string1 for
  2375.     the first occurence of any character contained IN string2
  2376.     and returns the location of the character.  Returns 0 if
  2377.     none of the characters occur.
  2378. Inp:    n is an integer.
  2379. Out:    integer.
  2380. Ex:    print instr2("abcbcacab","ca")    result: 1
  2381. See:    INSTR.
  2382.  
  2383. ~~INT
  2384. INT(x)
  2385.     The greatest integer not exceeding x.
  2386. Inp:    integer, real, rational.
  2387. Out:    integer.
  2388. Ex:    INT(12345/100) = 123,INT(-12345/100) = -124.
  2389. See:    FIX(x) and ROUND(x).
  2390.  
  2391. ~~IRND
  2392. IRND
  2393.     Integer valued random number from -32767 to 32767.
  2394. Note:    -32768 does not occur. In return, 0 appears twice as
  2395.     often as others.
  2396. Out:    integer i (-32767 <= i <= 32767).
  2397. Ex:    10    randomize
  2398.     20    for I=1 to 100
  2399.     30      print irnd;
  2400.     40    next
  2401.         displays 100 integer valued random numbers.
  2402. See:    RANDOMIZE, RND.
  2403.     appendix B for the algorithm.
  2404.  
  2405. ~~ISQRT
  2406. ISQRT(x)
  2407.     Integer part of the square root of x.
  2408. Note:    Returns precisely the largest integer not exceeding the
  2409.     theoretical value.
  2410. Inp:    integer.
  2411. Out:    integer.
  2412. Ex:    print isqrt(10)    result: 3
  2413. See:    SQRT.
  2414.  
  2415. ~~JUMP
  2416. JUMP
  2417.     Goes to the next "**", as in
  2418.     10    if a=1 then jump
  2419.     20    b=1
  2420.     30 **: c=1
  2421.  
  2422. Note:    It is easy to find where to jump unlike GOTO.
  2423.  
  2424. ~~KEY
  2425. KEY key_number,string
  2426.     Modifies the settings of function keys, etc.
  2427.     Key number is as follows:
  2428.     1  - 10 f1 - f10
  2429. Ex:    key 1,"run "+chr(0x22)+"pi"+chr(0x22)+chr(0x0d)
  2430.         assigns 'run "pi"<cr>' to function key #1.
  2431.  
  2432. ~~KILL
  2433. KILL "filename"
  2434.     Kills a program or a data file.  In the latter case, append
  2435.     a + just after the filename.
  2436. Note:    If the filename is without extension, the file is
  2437.     regarded as a program with ".UB".
  2438.     If "+" is added in place of extension, the file is
  2439.     regarded as data with ".UBD".
  2440.     To specify a file without extension, add "." to the
  2441.     filename.
  2442. See:    SET.
  2443.  
  2444. ~~KRO
  2445. KRO(m,n)
  2446.     Extended Kronecker's symbol for m and n.  Equivalent to
  2447.     Legendre's symbol (for quadratic residue) for odd prime n:-
  2448.     That is, 1 if m is quadratic residue modulo n, -1 if m is
  2449.     a non-quadratic residue, 0 if m can be divided by n.
  2450.     Also equivalent to Jacobi's symbol for odd composite n.
  2451.  
  2452. Inp:    integer.
  2453. Out:    integer (0, 1, or -1).
  2454. Ex:    print kro(3,5)    result:-1.
  2455.  
  2456.  
  2457. ~~LCOEFF
  2458. LCOEFF(polynomial)
  2459.     Coefficient of the term of highest degree of polynomial.
  2460. Ex:    A=poly(1,3,5):print lcoeff(A)    result: 5
  2461. See:    CCOEFF, COEFF.
  2462.  
  2463. ~~LDIR
  2464. LDIR "pathname"
  2465.     Outputs a list of files to the printer.
  2466.     Usually the pathname is simply the drive name (a:, b:,
  2467.     etc.).
  2468.     A wild card is allowed.
  2469. See:    the MS-DOS manual for detailed information.
  2470.     DIR.
  2471.  
  2472. ~~LEFT
  2473. LEFT(string[,n])
  2474.     n characters at the left end of a string.
  2475.     It returns one character when n is not given.
  2476. Ex:    print left("abcdefgh",3)    result:abc
  2477. See:    MID, RIGHT.
  2478.  
  2479. LEFT(packet[,n])
  2480.     The packet which contains the n members at the left end of
  2481.     the specified packet.
  2482. Note:    It returns a packet with one member when n is not given.
  2483.     Use MEMBER to get a member itself.
  2484. Ex:    print left(pack(1,2,3,4,5),3)    result:( 1, 2, 3)
  2485. See:    MEMBER, MID, RIGHT, PACK.
  2486.  
  2487. ~~LEN
  2488. LEN(x)
  2489.     Bit length of x.  LEN(0) = 0, LEN(1) = 1, LEN(5) = 3,
  2490. Note:    It returns byte length when argument is a string,
  2491.     number of data when argument is a packet, and number of
  2492.     terms (degree+1) when argument is a polynomial.
  2493. Inp:    any data.
  2494. Out:    integer.
  2495. Ex:    len(0)=0, len(1)=1, len(5)=3, len(65535)=16,
  2496.     len(65536)=17, len("abc")=3
  2497.     A=pack(1,2,3):print len(A)    result: 3
  2498.     A=poly(1,2,3):print len(A)    result: 3 (note deg(A)=2).
  2499.  
  2500. ~~LIST
  2501. LIST [linenumber1 or label1] [ - linenumber2 or label2]
  2502.     Displays the specified portion of the current program.
  2503.     To halt, press Control-S.  To quit, press Control-C.
  2504. Note:    To edit a program, EDIT, <ROLL_UP> and <ROLL_DOWN> are
  2505.     recommended.
  2506. See:    EDIT.
  2507.  
  2508. ~~LLIST
  2509. LLIST [linenumber1 or label1] [ - linenumber2 or label2]
  2510.     Same as LIST, but outputs to both the printer and the
  2511.     screen.
  2512. Note:    To halt, press Control-S.  To quit, press Control-C.
  2513.     Note that a printer with a buffer does not stop at
  2514.     once.
  2515.  
  2516. ~~LLOCATE
  2517. LLOCATE n
  2518.     Sends a carriage return (but not line feed) and n blanks to
  2519.     the printer.
  2520. See:    LOCATE.
  2521.  
  2522. ~~LOAD
  2523. LOAD "program_name"
  2524.     Reads the program into memory.  LOADing a programs from
  2525.     standard (ASCII) text files is slower because they need to
  2526.     be converted to the internal code.
  2527.     If you do not give the program_name, the list of programs
  2528.     is displayed so that you may select a program using the
  2529.     arrow keys and
  2530.     and <ENTER>.  (hit <ESC> to quit)
  2531. See:    APPEND, SAVE.
  2532.  
  2533. ~~LOCAL
  2534. LOCAL variable1[=value],variable2[=value], ...
  2535.     Defines local variables and initializes them (default = 0).
  2536. Note:    Local variables must be defined just after the
  2537.     subroutine/function definition.
  2538.     Variables defined by LOCAL are valid until the
  2539.     subroutine/function RETURNs.  They are distinguished
  2540.     from variables of the same name in the main program.
  2541.     Local variables are initialized to zero if the value is
  2542.     not specified.
  2543.     Do not LOCAL the arguments of the subroutine/function,
  2544.     since arguments are automatically defined as local
  2545.     variables.
  2546.         100    fnABC(X,Y,Z)
  2547.         110    local I,J,K,Z
  2548.     sets to 0  the value of Z passed by the main program.
  2549. Ex:     10    for I=1 to 10
  2550.      20      gosub *ABC(I)
  2551.      30     next
  2552.      40     end
  2553.     100     *ABC(X)
  2554.     110      local I    :' This 'I' is not the 'I' in the main
  2555.                 routine.
  2556.     120      for I=1 to X
  2557.     130        print X;
  2558.     140      next
  2559.     150      print
  2560.     160    return
  2561.  
  2562.     The variable I is used in both the main routine and the
  2563.     subroutine.
  2564.     The value assigned by LOCAL in line 110 does not affect
  2565.     the value of I in the main routine.
  2566. Note:    Variables already passed by address using "&" cannot be
  2567.     initialized by LOCAL.
  2568.  
  2569. ~~LOCATE
  2570. LOCATE x, y
  2571. LOCATE x
  2572. LOCATE , y
  2573.     Specifies the cursor position on the screen.
  2574. Note:    Locate X changes the x-coordinate.  The y-coordinate
  2575.     remains as it was.
  2576.     Locate ,Y changes the y-coordinate.  The x-coordinate
  2577.     remains as it was.
  2578. See:    LLOCATE.
  2579.  
  2580. ~~LOG
  2581. LOG(x)
  2582.     Natural logarithm of x.
  2583. Inp:    number.
  2584. Out:    real, complex number.
  2585. Ex:    print log(1.23)    result: 0.2070...
  2586. See:    appendix B for the algorithm.
  2587.  
  2588. ~~LOOP
  2589. LOOP - ENDLOOP
  2590.     Constructs an infinite loop.
  2591. Note:    You may jump out of the loop using GOTO.
  2592. Ex:    10    loop
  2593.     20    ...
  2594.     30    ...
  2595.     40    endloop
  2596.  
  2597.     is equivalent to:
  2598.  
  2599.     10    '
  2600.     20    ...
  2601.     30    ...
  2602.     40    goto 10
  2603.  
  2604.     However, the loop structure is emphasized in the former
  2605.     case.
  2606. See:    ENDLOOP.
  2607.  
  2608. ~~LOWER
  2609. LOWER(string)
  2610.     Translates characters to lowercase.
  2611. Inp:    string.
  2612. Out:    string.
  2613. Ex:    print lower("BecauseIt'sTime.")
  2614.         result:becauseit'stime.
  2615. See:    UPPER.
  2616.  
  2617. ~~LPRINT
  2618. LPRINT
  2619. 1) LPRINT expression
  2620.     LPRINT USING(x, y), expression
  2621.     LPRINT "string"
  2622.     LPRINT CHR(n)
  2623.     Outputs to the printer.
  2624. Note:    Multiple expressions can be output with one LPRINT
  2625.     statement.
  2626.     Expressions must be marked off with ";" or ",".
  2627.     "LPRINT A;B" prints the values without spaces in
  2628.     between.
  2629.     "LPRINT A,B" prints the value of B on the next
  2630.     8-character field.
  2631. See:    LLOCATE, ALEN, USING.
  2632. Note:    LPRINT may not function when the use of print.sys is 
  2633.     not declared in config.sys in MS-DOS version 3.1 and 
  2634.     later versions.
  2635.     Place the "print.sys" in the system disket of MS-DOS 
  2636.     and add the "config.sys" the following line (See MS-DOS
  2637.     manual for details.):
  2638.     device = print.sys
  2639. See:    MS-DOS manual for details.
  2640.  
  2641.  
  2642. 2) LPRINT = PRINT + LPRINT + "filename.UBD"
  2643.      Redirects the outputs of LPRINT statements to the
  2644.      screen (PRINT), the printer (LPRINT), a file
  2645.      ("filename.UBD"), or any combination of these.  No
  2646.      more than one file is allowed on the right-hand side.
  2647.      The file must be distinct from the one specified by
  2648.      the "PRINT = ..." construct.  The extension ".UBD" is
  2649.      needed by UBASIC's DIR and KILL commands.
  2650.      The outputs are redirected to NULL if nothing is on
  2651.      the right-hand side.
  2652.  
  2653. ~~LVLIST
  2654. LVLIST [line_number1 or label1][-line_number2 or label2]
  2655.     Outputs to the printer the list of variables used in the
  2656.     program.
  2657. See:    VLIST.
  2658.  
  2659. ~~LVXREF
  2660. LVXREF [variable]
  2661.     Outputs to the printer the cross-reference list for all (or
  2662.     the specified) varialbes.  Array names must be followed by
  2663.     a (.
  2664. See:    VXREF.
  2665.  
  2666. ~~LXREF
  2667. LXREF [line_number or label_1] [-line_number or label_2]
  2668.     Displays/prints the line numbers of the lines that
  2669.     reference the specified lines. Press Control-S to halt,
  2670.     Control-C to quit.
  2671. Note:    If line_number or label is not specified, all the line
  2672.     numbers and labels are regarded as the arguments.
  2673. See:    XREF.
  2674.  
  2675. ~~MAX
  2676. MAX(arg1,arg2,...)
  2677.     Returns the largest of the arguments.
  2678. Ex:    print max(1,3,2)    result: 3
  2679.     print max("d","abc","ef")    result:ef
  2680.         In string comparisons, the ASCII codes of the
  2681.     characters are compared in order.
  2682. See:    MIN.
  2683.  
  2684. ~~MELT
  2685. MELT ["filename"]
  2686.     Melts a FREEZEd program.
  2687. Note:    Filename should not have an extension as ".ICE" is 
  2688.     automatically added.
  2689.     If no filename is given, "UB.ICE" in the current 
  2690.     directory is used.
  2691.     The MELTed program cannot be CONTinued after a fatal
  2692.     error has occurred.  In that case, MELT it once again.
  2693.     Results are unpredictable if a file is modified after
  2694.     FREEZing the program in which it is OPENed.
  2695. See:    FREEZE.
  2696.  
  2697. ~~MEMBER
  2698. MEMBER
  2699.  
  2700. 1) MEMBER(string,n)
  2701.     n-th member of the specified string.
  2702.     The members of the string are marked off by "," or a
  2703.     space.  However, ","s or spaces between () are
  2704.     neglected.
  2705. Ex:    A="123,abcdefg,mid(B,1,2)"
  2706.     print member(A,1)    result:123
  2707.     print member(A,2)    result:abcdefg
  2708.     print member(A,3)    result:mid(B,1,2)
  2709. Note:    Use CUTSPC to delete the spaces if you do not want
  2710.     them to be regarded as delimiters.
  2711.     The return value is a string.  Use VAL to convert
  2712.     it to a number.
  2713.  
  2714. 2) MEMBER(packet,n)
  2715.     n-th member of the specified packet.
  2716. Ex:    print member(pack(11,22,33,44),3)    result: 33
  2717. See:    PACK.
  2718.  
  2719. 3) MEMBER(packet,n)=expression
  2720.     Replaces the n-th member of the specified packet.
  2721. Note:    If n is more than the current number of members,
  2722.     0 is assigned to the n-th member and all the
  2723.     members between the n-th and current members.
  2724. Ex:    A=pack(11,22,33,44):member(A,3)=55:print member(A,3)
  2725.         result: 55
  2726. See:    PACK.
  2727.  
  2728. ~~MID
  2729. MID
  2730. 1) MID(string,x,n)
  2731.     Substring which starts with the x-th character of the
  2732.     specified string and contains n characters.
  2733. Note:    To specify all the characters starting with the
  2734.     x-th, use "*" as n or specify a larger n than the
  2735.     length of the string.
  2736.     It returns one character if n is not given.
  2737. Ex:    A="abcdefg"
  2738.     print mid(A,2,3)    result:bcd
  2739.     print mid(A,2,100)    result:bcdefg
  2740.     print mid(A,2,*)    result:bcdefg
  2741.     print mid(A,2)        result:b
  2742. See:    LEFT, RIGHT.
  2743.  
  2744. 2) MID(packet,x,n)
  2745.     The portion of the specified packet which starts with
  2746.     the x-th member and contains n members.
  2747. Note:    Returns a packet with one member when n is not
  2748.     given.
  2749.     Use MEMBER to get a member itself.
  2750. Ex:    print mid(pack(11,22,33,44),2,2)    result: ( 22, 33)
  2751. See:    MEMBER, LEFT, RIGHT, PACK.
  2752.  
  2753. 3) MID(String_variable, x, n)=string
  2754.     Replaces n characters starting with the x-th character
  2755.     of the specified string_variable by specified string.
  2756. Note:    If the string is shorter then n characters, the
  2757.     rest of the characters are not replaced.
  2758.     If the string is longer, the rest of the string is
  2759.     neglected.
  2760. Ex:    A="abcdefg":mid(A,3,2)="xy":print A
  2761.         result:abxyefg
  2762. Note:    There is no MID statement which replaces the
  2763.     members of a packet.  Replace them one by one using
  2764.     MEMBER.
  2765.  
  2766. ~~MIN
  2767. MIN(arg1,arg2,...)
  2768.     Returns the smallest of the arguments.
  2769. Ex:    print min(1,3,2)    result: 1
  2770.     print min("d","abc","ef")    result:abc
  2771.         In string comparisons, the ASCII codes of the
  2772.     characters are compared in order.
  2773. See:    MAX.
  2774.  
  2775. ~~MOB
  2776. MOB(n)
  2777. See:    MOEB
  2778.  
  2779. ~~MODPOW
  2780. MODPOW(a,b,n)
  2781.     (a to the b) mod n.  Mod is taken each time a is raised in
  2782.     order not to overflow.  b >= 0, n > 0.
  2783. Note:    If b = 0, it returns 1 neglecting the value of a.
  2784. Inp:    b must be integer b >= 0
  2785.     a and n must be the same type: integer, polynomial or
  2786.     modpolynomial. if a is integer then n must be positive.
  2787. Out:    same as a
  2788. Ex:    print modpow(12,34,56)    result: 16
  2789.  
  2790. ~~MODINV
  2791. MODINV(a,n)
  2792.     Gives x such that a * x mod n = 1,  0 < x < n.
  2793.     It returns 0 if no such x exists, i.e. if a and n are not
  2794.     coprime.
  2795. Inp:    integer (n > 0).
  2796. Out:    integer.
  2797. Ex:    print modinv(23,45)    result: 2
  2798.  
  2799. ~~MODSQRT
  2800. MODSQRT(a,p)
  2801.     Gives x such that x^2 mod p = a, 0 <= x < p.
  2802. Inp:    integers(< 2^16 or < 2^32). a must be a square modulo p,
  2803.     p must be a prime number.
  2804. Out:    integer.
  2805.  
  2806. ~~MODULUS
  2807. MODULUS = expression
  2808.     Sets the modulus (which must be prime, =< 65535) used in
  2809.     the calculation of polynomials.
  2810.  
  2811.     Set modulus = 0 (default value) when calculating normal
  2812.     polynomials (with integral, rational or complex
  2813.     coefficients).
  2814. Note:    UBASIC allows polynomials whose coefficients are
  2815.     integers taken modulo a prime number.
  2816. Ex:    modulus=2:A=5*_X^2+6*_X+7:print A    result: 1*X^2 + 1
  2817. Note:    Do not change the modulus during calculation with
  2818.     polynomials.
  2819.  
  2820. MODULOUS
  2821.     Current value of modulus.
  2822.  
  2823. ~~MOEB
  2824. MOEB(n)
  2825.     Moebius' function.
  2826.     0 if n has a square factor.
  2827.     If n has no square factor, 1 if n has an even number of
  2828.     prime factors, -1 if n has an odd number of prime factors.
  2829. Inp:    integer n (1 <= n <= 65536^2-1 = 4294967295).
  2830. Out:    integer.
  2831. Ex:    print mob(105)    result: -1
  2832.  
  2833. ~~MONIC
  2834. MONIC(polynomial)
  2835.     Monic polynomial obtained by dividing the argument by the
  2836.     coefficient of the highest degree.
  2837. Ex:    A=2*_x+1:print monic(A)
  2838.         result:    X + 1//2    if modulus = 0
  2839.             X + 2        if modulus = 3
  2840.             X + 3        if modulus = 5.
  2841.  
  2842. ~~NEG
  2843. NEG variable1 [,variable2,... ]
  2844.     "NEG A" is equivalent to "A = -A", but faster.
  2845. Ex:    neg A,B,C
  2846.         changes signs of A, B, C.
  2847. See:    CLR, DEC, INC.
  2848.  
  2849. NEG BLOCK array(index,index...)
  2850.     Changes the signs of the specified array members.
  2851. Ex:    neg block A(0..10)
  2852.         changes signs of the members from A(0) to A(10)
  2853.     neg block A(2,1..2)
  2854.         changes signs of A(2,1) and A(2,2)
  2855. See:    BLOCK for details.
  2856.  
  2857. ~~NEW
  2858. NEW
  2859.     Deletes the current program and variables.
  2860. Note:    A program NEWed by mistake can be REVIVEd.
  2861. See:    REVIVE.
  2862.  
  2863. ~~NOP
  2864. NOP
  2865.     No operation.  When the TRON command does not function
  2866.     properly (e.g. in the case of multi-statements), put an NOP
  2867.     just before the statement to be traced.
  2868. See:    TRON, TROFF.
  2869.  
  2870. ~~NOT
  2871. NOT
  2872.     IF NOT
  2873.     WHILE NOT
  2874.     UNTIL NOT
  2875.     Changes logical values.
  2876. Note:    This is to emphasize "If .... is not true".
  2877. Ex:    while not eof(1)
  2878.       input #1,A:print A
  2879.     wend
  2880.  
  2881.         is easier to understand than:
  2882.  
  2883.     while eof(1)=0
  2884.       input #1,A:print A
  2885.     wend
  2886.  
  2887. ~~NUM
  2888. NUM(argument)
  2889.     Numerator of the argument.
  2890. Inp:    integer, rational.
  2891. Ex:    print num(2//3)    result: 2
  2892. See:    DEN.
  2893.  
  2894. ~~NXTPRM
  2895. NXTPRM(x)
  2896.     The smallest prime greater than x.  It returns 0 if either
  2897.     x < 0 or the result is greater than 2 to the 32nd.  x may
  2898.     be a noninteger.
  2899. Inp:    integer, real.
  2900. Out:    integer.
  2901. Ex:    print nxtprm(123.45)    result: 127
  2902.  
  2903. ~~NEXT
  2904. NEXT
  2905. See:    FOR.
  2906.  
  2907. ~~ODD
  2908. ODD(x)
  2909.     1 if x is odd, 0 if even.  x must be an integer.
  2910. Inp:    integer.
  2911. Out:    integer (0 or 1).
  2912. Ex:    print odd(10),odd(11)    result: 0    1
  2913. See:    EVEN.
  2914.  
  2915. ~~ON
  2916. ON
  2917. See:    ERROR.
  2918.  
  2919. ~~OPEN
  2920. OPEN
  2921. 1) OPEN "filename" FOR INPUT (or OUTPUT or APPEND) AS #n
  2922.     Opens a sequential data file to be written and read by
  2923.     "PRINT #n, ..." and "INPUT #n, ..." commands,
  2924.     where n = 1, 2, 3, 4.
  2925.     Do not add a + after the filename.  If the POINT value
  2926.     is changed after the file was written, truncating or
  2927.     padding with zeros can occur.
  2928.     If the file specified in "OPEN...FOR APPEND" is not
  2929.     found, a new file named "file_name" is created.
  2930. Note:    10 files (#1 ... #10) can be OPENed at the same
  2931.     time.  When you cannot open 10 files, increase the
  2932.     number of open files declared in "config.sys".
  2933.     "files = 20" is recommended.
  2934.     Filename does not contain an extension.  Do not add
  2935.     "+" to the filename even if it is a data file.
  2936. See:    CLOSE, EOF, INPUT #, PRINT #.
  2937.  
  2938. 2) OPEN "filename(with extension)" FOR INPUT (or OUTPUT or
  2939. APPEND) AS #n
  2940.     Opens a file in text-file form(=ASCII form).
  2941. Note:    10 files can be OPENed at the same time.
  2942.     Add "." to specify a filename without extension.
  2943. See:    CLOSE, EOF, INPUT #, PRINT #.
  2944.  
  2945. 3) OPEN "filename" AS FILEn(m1) [WORD m2]
  2946.     Uses files as an external array, where n = 1, 2, 3.
  2947.     The upper bound for the array index, m1, may be greater
  2948.     than 65535.  The word size of each array element is
  2949.     m2 (or 8 if not specified).  Protected files can be
  2950.     read, but not written.
  2951.  
  2952. Ex:    open "filename" as file1(n) [word x]
  2953.         makes a new file.
  2954.     open "filename" as file1
  2955.         opens an existing file.
  2956. Note:    Filename does not contain an extension as ".ubd" is
  2957.     automatically added.
  2958. See:    CLOSE.
  2959.     "External arrays" for details.
  2960.  
  2961. ~~OR
  2962. OR{expression1,expression2,...}
  2963.     0 if all the expressions are zero, 1 otherwise.
  2964.     If one of the argument is nonzero, it returns 1 at once
  2965.     without evaluating the following expressions.
  2966. Inp:    expressions.
  2967. Out:    integer (0 or 1).
  2968. Ex:    if or{A,B,...} then
  2969.  
  2970.     When the expressions between {} are long,
  2971.     continuation of lines (:) is allowed as follows:
  2972.  
  2973.     if or{A,
  2974.       :B,
  2975.       :...}
  2976.     :then
  2977.  
  2978. ~~OUT
  2979. OUT port#,expression
  2980.     Outputs a value to the specified port.
  2981.  
  2982. ~~PACK
  2983. PACK(arg1,arg2,...)
  2984.     Makes data a packet.
  2985. Note:    It assigns multiple data to a variable.
  2986.     Use MEMBER to get a member of a packet.
  2987. Ex:    A=pack(1,2,3):print A    result: ( 1, 2, 3)
  2988. See:    MEMBER, LEFT, MID, RIGHT.
  2989.  
  2990. ~~PEEK
  2991. PEEK(address)
  2992.     The byte at the specified address.
  2993. Note:    Segment must be specified by DEFSEG.
  2994. See:    DEFSEG, PEEKW, PEEKS, POKE, VARPTR.
  2995.  
  2996. ~~PEEKW
  2997. PEEKW(address)
  2998.     The word at the specified address.
  2999. Note:    Segment must be specified by DEFSEG.
  3000. See:    DEFSEG, PEEK, PEEKS, POKEW, VARPTR.
  3001.  
  3002. ~~PEEKS
  3003. PEEKS(address,n)
  3004.     n bytes at the specified address.
  3005. Note:    Segment must be specified by DEFSEG.
  3006. Out:    string.
  3007. See:    DEFSEG, PEEK, PEEKW, POKES, VARPTR.
  3008.  
  3009. ~~PI
  3010. PI(x)
  3011.     PI times x.  This is more precise for large x.
  3012.     ex. 10000*#pi contains an error in the least significant
  3013.     4 digits, but pi(10000) does not.
  3014.     The precision depends on the current value of POINT.
  3015.     (maximum:541 words)
  3016. Inp:    number.
  3017. Out:    real, complex number.
  3018. Ex:    print pi(100)    result: 314.1592...
  3019. See:    #pi.
  3020.  
  3021. ~~POINT
  3022. POINT expression
  3023. POINT *
  3024.     Specifies the number of words, n (= 2, 3, ..., 525), for
  3025.     the decimal part of the variables.  One word is about 4.8
  3026.     decimal places;  100 decimal places are 21 words;
  3027.     1000 decimal places are 208 words.  "POINT *" sets the
  3028.     largest allowed value.  When multiplications, divisions, or
  3029.     function calls are involved, n must be no more than 260,
  3030.     otherwise overflow can occur.  When complex numbers are
  3031.     involved, n must be no more than 130.
  3032.     This statement closes all the files, so it must be placed
  3033.     at the beginning of the program.  Do not use this statement
  3034.     inside a subroutine or a function, or when variables are
  3035.     already assigned non-integer values.
  3036.     No message is displayed if negative n is specified.
  3037.     PRINT POINT displays the current POINT value.
  3038.  
  3039. ~~POKE
  3040. POKE address,expression
  3041.     Stores a byte value at the specified address.
  3042. Note:    The segment must be specified by DEFSEG.
  3043. See:    DEFSEG, PEEK, POKEW, POKES, VARPTR.
  3044.  
  3045. ~~POKEW
  3046. POKEW address,expression
  3047.     Stores a word value at the specified address.
  3048. Note:    The segment must be specified by DEFSEG.
  3049. See:    DEFSEG, PEEK, POKEW, POKES, VARPTR.
  3050.  
  3051. ~~POKES
  3052. POKES address,string
  3053.     Stores a string at the specified address.
  3054. Note:    The segment must be specified by DEFSEG.
  3055. Ex:    defseg=0x8000:A="ABC":pokes 0,A
  3056.         stores 0x41,0x42,0x43 at the addresses 8000:0001,
  3057.     0002,0003, respectively, where '0x...' indicates a
  3058.     hexadecimal number.
  3059. See:    DEFSEG, PEEK, POKEW, POKES, VARPTR.
  3060.  
  3061. ~~POLY
  3062. POLY(coeff0,coeff1,coeff2,...)
  3063.     A polynomial with the arguments as coefficients.
  3064. Ex:    A=poly(1,2,3):print A    result: 3*X^2 + 2*X + 1
  3065. See:    COEFF.
  3066.  
  3067. ~~POSX
  3068. POSX
  3069.     The x-coordinate of the current cursor position.
  3070.     (0 <= POSX <= 79)
  3071. Ex:    locate posx-1
  3072.         moves the cursor 1 column to the left.
  3073.  
  3074. ~~POSY
  3075. POSY
  3076.     The y-coordinate of the current cursor position.
  3077.     (0 <= POSY <= 24)
  3078. Ex:    locate posy-1
  3079.         moves the cursor up 1 line.
  3080.  
  3081. ~~PRINT
  3082. PRINT expression or "string" or CHR(n) or etc.
  3083.     Outputs the value of the expression, the string, the
  3084.     character whose ASCII code is n, or the current time to the
  3085.     screen. "PRINT A;B" prints the values without spaces in
  3086.     between.  "PRINT A,B" prints the value of B on the next
  3087.     8-character field.  Press Control-S for halt/restart
  3088.     toggle.
  3089. See:    LOCATE, ALEN, USING.
  3090.  
  3091. PRINT = PRINT + LPRINT + "filename"
  3092.     Redirects the output of PRINT statements.
  3093.     "PRINT = PRINT" cancels the redirection.
  3094. Note:    No more than one file is allowed on the right-hand side.
  3095.     The file must be distinct from the one specified by the
  3096.     "LPRINT = ..." construct.
  3097.     The output is redirected to NUL if nothing is on the
  3098.     right-hand side.
  3099. See:    LPRINT =
  3100.  
  3101. ~~PRINT #
  3102. PRINT #n,expression
  3103.     PRINTs to file #n.
  3104. Note:    Multiple expressions can be output with one PRINT #
  3105.     statement.
  3106.     Expressions must be marked off with ";" or ",".
  3107. See:    OPEN.
  3108.  
  3109. ~~PRM
  3110. PRM(n)
  3111.     n-th prime number.  PRM(12251) is the greatest prime less
  3112.     than (2 to the 17th).
  3113. Inp:    integer n (0 <= n <= 12251).
  3114. Out:    integer.
  3115. Ex:    (prm(0)=1), prm(1)=2, prm(2)=3, ... prm(12251)=131071
  3116.  
  3117. ~~PRMDIV
  3118. PRMDIV(n)
  3119.     The least prime divisor of n.  It returns 0 if n is greater than
  3120.     2^34 and has no divisor less than 2^17.
  3121. Inp:    integer.
  3122. Out:    integer.
  3123. Ex:    print prmdiv(105)    result: 3
  3124.  
  3125. ~~RANDOMIZE
  3126. RANDOMIZE [n]
  3127.     Initializes the random number generator with n.
  3128.     (0 <= n <= 65535)
  3129. Note:    To get a random number, use RND or IRND.
  3130.     The current time is used if no n is given.
  3131. See:    RND, IRND.
  3132.  
  3133. ~~RE
  3134. RE(x)
  3135.     Real part of x.
  3136. Inp:    number.
  3137. Out:    number.
  3138. Ex:    print re(123+456#i)    result: 123
  3139. See:    CONJ, IM.
  3140.  
  3141. ~~READ
  3142. READ var1 [,var2,...]
  3143.     Reads from the DATA statements.
  3144. Ex:     10    restore 100
  3145.      20    read a,b,c
  3146.      30    print a;b;c
  3147.      40    end
  3148.     100    data 11,22,33
  3149.         result: 11 22 33
  3150. See:    DATA, RESTORE.
  3151.  
  3152. ~~REDUCE
  3153. REDUCE variable1,variable2
  3154.     Divides two integer variables by their greatest common
  3155.     divisor.
  3156. Note:    The numerator and denominator of a rational number can
  3157.     be REDUCEd.
  3158.     Variable2 becomes positive.
  3159. Inp:    integer.
  3160. See:    GCD.
  3161.  
  3162. ~~REM
  3163. REM or '
  3164.     Causes the rest of the line to be ignored.
  3165. Note:    REM can be replaced by "'".
  3166.     Note that a continued line is not ignored.
  3167. Ex:    10    print 1:'test:print 2
  3168.  
  3169.     In the above line "print 2" is not executed.
  3170.     However in the following lines it is executed:
  3171.  
  3172.     10    print 1:'test
  3173.     20    :print 2
  3174.  
  3175. ~~RENAME
  3176. RENAME "old filename" to "new filename"
  3177.     Changes filename.
  3178.     If the extension is not specified, it is regarded as ".UB".
  3179.  
  3180. ~~RENUM
  3181. RENUM [start_of_new_line_numbers] [,start_of_old_line_numbers]
  3182.     Renumbers the lines with increments of 10.  The new line
  3183.     numbers start with 10 if not specified.
  3184.  
  3185. ~~REPEAT
  3186. REPEAT statements UNTIL expression
  3187.     Repeats <statements> until <expression> is nonzero.
  3188. Note:    ":" between REPEAT and statements can be omitted.
  3189.     It can be omitted alsobetween statements and UNTIL.
  3190.     You may jump out of the loop using GOTO.
  3191.  
  3192. ~~RES
  3193. RES
  3194.     Residue (remainder) of the most recent integer division
  3195.     including division of complex numbers with integer
  3196.     components and division of polynomials.
  3197. Note:    Noninteger divisions and function evaluations can
  3198.     destroy RES.
  3199.     Assign it to a variable if you do not use it
  3200.     immediately after the integer division.
  3201.     Evaluation of ISQRT(x) (when x is an integer) sets RES
  3202.     to x - ISQRT(x)^2, which is zero if x is a square
  3203.     number.
  3204. Ex:    A=35:A1=A\10:A0=res
  3205.         assigns 3 to A1 and 5 to A0.
  3206. Out:    integer, complex number, polynomial.
  3207.  
  3208. ~~RESTORE
  3209. RESTORE line_number or label
  3210.     The next READ statement reads from the first DATA
  3211.     statements below the specified line.
  3212. See:    DATA, READ.
  3213.  
  3214. ~~RESTORE #
  3215. RESTORE #n
  3216.     Equivalent to "CLOSE #n: OPEN #n".
  3217. See:    EOF, OPEN.
  3218.  
  3219. ~~RETURN
  3220. RETURN
  3221.     Returns from the subroutine.
  3222. See:    GOSUB.
  3223.  
  3224. ~~RETURN
  3225. RETURN(return_value)
  3226.     Returns from the subroutine with a return value.
  3227. See:    FN.
  3228.  
  3229. ~~REVIVE
  3230. REVIVE
  3231.     Undeletes the program just NEWed.
  3232. See:    NEW.
  3233.  
  3234. ~~RIGHT
  3235. RIGHT(string[,n])
  3236.     n characters at the rignt end of a string.
  3237.     It returns one character when n is not given.
  3238. See:    LEFT, MID.
  3239.  
  3240. ~~RIGHT
  3241. RIGHT(packet[,n])
  3242.     Packet which contains n members at the right end of
  3243.     specified packet.
  3244. Note:    Returns a packet with one member when n is not given.
  3245.     Use MEMBER to get a member itself.
  3246. See:    MEMBER, LEFT, MID, PACK.
  3247.  
  3248. ~~RND
  3249. RND
  3250.     Real-valued random number between 0 and 1.  The precision is
  3251.     determined by the current POINT.  To change the sequence,
  3252.     use RANDOMIZE.
  3253. Out:    decimal number x (0 <= x < 1).
  3254. Ex:    10    randomize
  3255.     20    for I=1 to 100
  3256.     30      print rnd;
  3257.     40    next
  3258.         displays 100 random numbers.
  3259. See:    RANDOMIZE, IRND.
  3260.     appendix B for the algorithm.
  3261.  
  3262. ~~ROUND
  3263. ROUND(x)
  3264.     Integer nearest to x.
  3265. Inp:    integer, real, rational.
  3266. Out:    integer.
  3267. Ex:    round(1.3)=1,round(-1.7)=-2,round(0.5)=1,round(-0.5)=-1
  3268. See:    FIX, INT.
  3269.  
  3270. ~~RUN
  3271. RUN ["program_name"]
  3272.     [Loads and] runs the program.
  3273.     When a program name is not given, a list of programs is
  3274.     displayed so that you may select a program using arrow keys
  3275.     and <ENTER>.
  3276.  
  3277. ~~SAVE
  3278. SAVE "program_name"
  3279.     Stores the current program on to a disk in intermediate-
  3280.     code form.
  3281. Note:    If no file name is given, the current date and time are
  3282.     used as the program name.
  3283.     Use ASAVE to save a program in text-file form.
  3284. See:    APPEND, ASAVE, LOAD.
  3285.  
  3286. ~~SET
  3287. SET "filename","P"
  3288. SET "filename"," "
  3289.     Sets and resets the write protection flag of the file,
  3290.     respectively.
  3291.     A data file's filename requires a "+" after it.
  3292. Note:    The extension is regarded as ".UB" if not given
  3293.     (".UBD" when "+" is added).
  3294.     To specify a file with no extension, add "." to the
  3295.     filename.
  3296. See:    DIR, KILL.
  3297.  
  3298. ~~SFT
  3299. SFT(x,b)
  3300.     x is shifted left (or right if b < 0) by b bits.
  3301.     SFT(x, 1) = x * 2,  SFT(1, -1) = 0,  SFT(1.0, -1) = 0.5.
  3302. Inp:    x is an integer or a real, b is an integer.
  3303. Out:    same type as x.
  3304. Ex:    print sft(123,1)    result: 246
  3305.     print sft(123.0,1)    result: 246.0
  3306.     print sft(123,-1)    result: 61
  3307.     print sft(123.0,-1)    result: 61.5
  3308.  
  3309. ~~SGN
  3310. SGN(x)
  3311.     1, 0, -1 for x > 0, x = 0, x < 0, respectively.
  3312. Inp:    integer, real, rational.
  3313. Out:    integer (-1, 0, 1).
  3314.  
  3315. ~~SIN
  3316. SIN(x)
  3317.     Sine of x.
  3318. Inp:    number.
  3319. Out:    number.
  3320. Ex:    print sin(1.23)    result: 0.9424...
  3321. See:    COS, TAN.
  3322.     appendix B for the algorithm.
  3323.  
  3324. ~~SINH
  3325. SINH(x)
  3326.     Hyperbolic sine of x.
  3327.     (exp(x)-exp(-x))/2.
  3328. Inp:    number.
  3329. Out:    number.
  3330. Ex:    print sinh(1.23)    result: 1.5644...
  3331. See:    COSH.
  3332.     appendix B for the algorithm.
  3333.  
  3334. ~~SKIP
  3335. SKIP
  3336. See:    TRON
  3337.  
  3338. ~~SPC
  3339. SPC(n)
  3340.     Equivalent to n blanks.  Use with PRINT or LPRINT.
  3341. Inp:    integer.
  3342. Out:    string.
  3343. Ex:    print spc(20);
  3344.         displays 20 blanks.
  3345. See:    LOCATE, LLOCATE, TAB.
  3346.  
  3347. ~~SQRT
  3348. SQRT(x)
  3349.     Square root of x.  SQRT(2) = SQRT(2.0) = 1.4142....
  3350.     If x is not a nonnegative real number then the solution
  3351.     which has nonnegative real part is given.
  3352.     SQRT(4) is 2.0 not 2 (same value but different type).
  3353. Inp:    number.
  3354. Out:    number.
  3355. Ex:    Both sqrt(2) and sqrt(2.0) are 1.4142....
  3356. See:    ISQRT.
  3357.     appendix B for the algorithm.
  3358.  
  3359. ~~STEP
  3360. STEP
  3361. See:    FOR.
  3362.  
  3363. ~~STOP
  3364. STOP
  3365. 1) Stops running.
  3366. Note:    Program halts at a STOP statement.  Control-C also
  3367.     halts the execution.  The execution can be continued by
  3368.     CONT.
  3369.     However, CONT may not work if non-syntax errors have
  3370.     occurred while the program is halted.  Changing the
  3371.     values of variables affects the results after the
  3372.     execution is CONTinued.
  3373.     Be careful alsoabout the value of RES.
  3374.  
  3375. 2) Stops tracing.
  3376. Note:    When STOP is used with TRON, the program halts before
  3377.     the execution of each line.
  3378. See:    TRON.
  3379.  
  3380. ~~STR
  3381. STR(n)
  3382.     Decimal expression of n.
  3383. Inp:    number.
  3384. Out:    string.
  3385. Ex:    A=1+#i:print right(str(A),3)    result:+#i
  3386.  
  3387. ~~STRINPUT
  3388. 1) STRINPUT ["message"] variable
  3389.     Inputs a string from the keyboard to the specified
  3390.     variable.
  3391. Note:    Unlike INPUT, the string must not be put between "".
  3392.     Do not delete the prompt "?".  If it is deleted,
  3393.     add "?" at the beginning of the string.
  3394.     When only <ENTER> is hit, INPUT prompts you to
  3395.     re-enter, but STRINPUT assigns a null string.
  3396. See:    INPUT.
  3397.  
  3398. 2) STRINPUT = "filename"
  3399.     Redirects the input to the specified ASCII file.
  3400.     STRINPUT = STRINPUT cancels the redirection.
  3401. See:    INPUT.
  3402.  
  3403. ~~SWAP
  3404. SWAP var1,var2
  3405.     Swaps the contents of the two variables of the same type.
  3406. Ex:    A=1:B=2:swap A,B:print A;B    result: 2 1
  3407.  
  3408. SWAP BLOCK array1(index, index, ...), [BLOCK] array2(index,
  3409. index, ...)
  3410.     Swaps the contents of the two arrays of the same type.
  3411. Note:    It swaps all the members if the indices are not
  3412.     specifed.
  3413.     The number of specified members must be the same but
  3414.     the composition may vary.
  3415.     If overlapping areas of one array are specified, double
  3416.     exchanging occurs and results are unpredictable.
  3417. Ex:    swap block A(0..9),block B(1..10)
  3418.         swaps A(0) ... A(9) with B(1) ... B(10).
  3419.     swap block A(2,1..3),block B(2..4)
  3420.         swaps A(2,1),A(2,2),A(2,3) with B(2),B(3),B(4).
  3421. See:    BLOCK.
  3422.  
  3423. ~~SYSTEM
  3424. SYSTEM
  3425.     Returns to DOS.
  3426.  
  3427. ~~TAB
  3428. TAB(n)
  3429.     Specifies the column for PRINT and LPRINT.  It is ignored
  3430.     when n is less than the current column position on the
  3431.     screen.
  3432. Note:    It outputs blanks between the current cursor position
  3433.     and the specified x-coordinate.  It just moves the
  3434.     cursor if n is negative.
  3435. Inp:    integer.
  3436. Out:    none.
  3437. See:    LOCATE, LLOCATE.
  3438.  
  3439. ~~TAN
  3440. TAN(x)
  3441.     Tangent of x.
  3442. Inp:    number.
  3443. Out:    number.
  3444. Ex:    print tan(1.23)    result: 2.8198...
  3445. See:    COS, SIN.
  3446.     appendix B for the algorithm.
  3447.  
  3448. ~~THEN
  3449. THEN
  3450. See:    IF.
  3451.  
  3452. ~~TIME
  3453. TIME
  3454.     CLR TIME sets the time to 00:00:00.  PRINT TIME displays
  3455.     the time.
  3456.  
  3457. ~~TO
  3458. TO
  3459. See:    FOR.
  3460.  
  3461. ~~TROFF
  3462. TROFF
  3463.     Cancels TRON.
  3464.     You may restart the program by CONT or TRON.
  3465.  
  3466. ~~TRON
  3467. TRON [STOP] [SKIP]
  3468.     Displays each line number before execution.  If STOP is
  3469.     specified, the line number is displayed, and the program is
  3470.     halted until <Enter> is pressed.  If SKIP is specified,
  3471.     deeper subroutine calls are not traced.
  3472.     TRONs and TROFFs may be specified in the program to debug a
  3473.     portion of the program.  Tracing may be hindered by a GOTO,
  3474.     GOSUB or a preceding FOR, WHILE or REPEAT.  For example,
  3475.     line 20 of the following program may not be traced.
  3476.  
  3477.     10    for I=0 to 10
  3478.     20      print I
  3479.     30    next
  3480.  
  3481.     If line 20 is not traced, rewrite it as
  3482.  
  3483.     20 nop: print I
  3484.  
  3485. Note:    Any statement which does not modify the program may be
  3486.     executed while the program is halted.
  3487.     You may place TRON and TROFF in the middle of the
  3488.     program to check the specified part.
  3489. Ex:    10    gosub *A
  3490.     20    end
  3491.     30    *A
  3492.     40      tron skip
  3493.     50      gosub *B
  3494.     60    return
  3495.     70    *B
  3496.     80      print "now in line 80"
  3497.     90    return
  3498.         result:
  3499.         $    50 now in line 80
  3500.         $    60 $    20
  3501.         OK
  3502.         (*B is not traced.)
  3503.  
  3504. ~~TYPE
  3505. TYPE(argument)
  3506.     Type of the argument.
  3507.     Integer=1, rational=2, real=3, complex number=4, string=5,
  3508.     packet=6, polynomial=7, mod polynomial=8.
  3509. See:    ATTRIB.
  3510.  
  3511. ~~UNTIL
  3512. UNTIL
  3513. See:    REPEAT.
  3514.  
  3515. ~~UPPER
  3516. UPPER(string)
  3517.     Translates characters to uppercase.
  3518. Inp:    string.
  3519. Out:    string.
  3520. Ex:    print upper("This is a pen.")    result:THIS IS A PEN.
  3521. See:    LOWER.
  3522.  
  3523. ~~USEEMA
  3524. USEEMA
  3525.     Declares the use of EMA-arrays.
  3526. Note:    Do not put a space between USE and EMA.
  3527. See:    EMA-array.
  3528.  
  3529. ~~USING
  3530. USING
  3531.     PRINT USING(x, y), expression
  3532.     LPRINT USING(x, y), expression
  3533.     The parameters x and y specify the numbers of digits for
  3534.     the integer and fractional parts to be output, respectively.
  3535.     The output is rounded.
  3536.     Sign is included in the integer part.
  3537. Ex:    print using(3, 2), 9.999
  3538.         result: 10.00
  3539.     print using(3, 5),1.234567
  3540.         result: 1.23457
  3541. Note:    Do not put a space between "using" and "(", or
  3542.     "using" will be regarded as the name of variable.
  3543.  
  3544. ~~VAL
  3545. VAL(string)
  3546.     Value expressed by the specified string.
  3547. Note:    The argument may be a function or a variable.
  3548.     It is recommended that the string should be ENCODEd
  3549.     when the same string is being specified several times.
  3550. Inp:    string.
  3551. Out:    number, string.
  3552. Ex:    X=2:print val("X+X^2")    result: 6
  3553. See:    DECODE, ENCODE, EVAL.
  3554.  
  3555. VAL(polynomial,x)
  3556.     Value of the polynomial as evaluated for the given x.
  3557. Inp:    x is a number or a polynomial.
  3558. Out:    number, polynomial.
  3559. Ex:    A=poly(0,1,1):print val(A,2)    result: 6
  3560.  
  3561. VAL(modpolynomial,x)
  3562.     Value of the polynomial modulo a prime as evaluated for
  3563.     the given x.
  3564. Inp:    x is an integer.
  3565. Out:    integer.
  3566. Ex:    modulus=5:A=poly(0,1,1):print val(A,2)    result: 1
  3567.  
  3568. ~~VARPTR
  3569. VARPTR(variable)
  3570.     Address of the specified variable.
  3571. Note:    It returns a 32 bit value.  The upper 16 bits are the
  3572.     segment address while the lower 16 bits are the offset
  3573.     address.
  3574. See:    DEFSEG, PEEK, POKE.
  3575.  
  3576. ~~VCHG
  3577. VCHG [start_line_number or label ,] old_var_name to new_var_name
  3578.     Replaces variable or array names from the specified line to
  3579.     the end of the program.
  3580. Note:    Ordinary variables cannot be changed into arrays, or
  3581.     vice versa.
  3582.     Arrays cannot be specified with indices.
  3583.     "vchg ABCD to ABcd" does not change the name as "ABCD"
  3584.     and "Abcd" are regarded as the same.  In this case,
  3585.     execute "vchg ABCD to AAAA" and "vchg AAAA to ABcd" for
  3586.     example.
  3587. Ex:    VCHG A,A#    VCHG A%,B#    VCHG A(),B#()
  3588.         The following usages are invalid:
  3589.     VCHG A,A()  VCHG A(),A    VCHG A(1),B(1)
  3590.  
  3591. ~~VLIST
  3592. VLIST [line_number1 or label1][-line_number2 or label2]
  3593.     Displays/prints the list of variables.
  3594. See:    LVLIST.
  3595.  
  3596. ~~VXREF
  3597. VXREF [variable]
  3598.     Displays/prints the cross-reference list for all (or the
  3599.     specified) variables.  Array names must be followed by a (.
  3600.     APPEND, VLIST, VXREF and VCHG are introduced to facilitate
  3601.     modular coding in the framework of BASIC.  LOAD the first
  3602.     module and APPEND the next.
  3603.     Then use VXREF to see if variable names coincide, in which
  3604.     case use VCHG to change the names.
  3605. See:    LVXREF.
  3606.  
  3607. ~~WEND
  3608. WEND
  3609. See:    WHILE.
  3610.  
  3611. ~~WHILE
  3612. WHILE expression statements WEND
  3613.     Executes <statements> while <expression> is nonzero.
  3614. Note:    You may jump out of the loop using GOTO.
  3615. Ex:    10    A=input$(1)
  3616.     20    while and{A<>"N",A<>"n"}
  3617.     30      print A;
  3618.     40      A=input$(1)
  3619.     50    wend
  3620.         inputs a character from the keyboard and displays it
  3621.     until "N" or "n" is entered.
  3622.  
  3623. ~~WIDTH
  3624. WIDTH 80,number_of_lines
  3625.     Specifies the number of lines displayed in the text screen.
  3626. Note:    The number_of_lines must be 20 or 25.
  3627.     The number of characters in one line is fixed at 80.
  3628.  
  3629. ~~WORD
  3630. WORD expression
  3631. WORD *
  3632.     Specifies the length (in words) of a long variable.
  3633. Note:    The maximum length is 542 words unless the system
  3634.     notifies otherwise (when the memory is scarce).  WORD
  3635.     alsocloses all open files and clears the variables
  3636.     except simple short ones.  WORD does not change
  3637.     execution speed because calculations are always done in
  3638.     542 words.
  3639.     WORD must be placed at the beginning of the program.
  3640.     "WORD *" specifies the maximum length allowed.
  3641.     No message is displayed if a negative value is
  3642.     specified.
  3643.     PRINT WORD displays the current value set by WORD.
  3644.     WORD cannot be used in subroutines/functions.
  3645.  
  3646. open ...  as ... WORD
  3647.     Specifies the length (in words) of a member of an external
  3648.     array.
  3649. See:    OPEN.
  3650.  
  3651. ~~XREF
  3652. XREF [line_number or label_1] [-line_number or label_2]
  3653.     Displays/prints the line numbers of the lines that
  3654.     reference the specified lines (or all the lines).
  3655.     Press Control-S to halt, Control-C to quit.
  3656. See:    LXREF.
  3657.  
  3658. ~~Lesson 1.
  3659. Lesson 1.
  3660.  
  3661.   To display message, write
  3662. print "test"<cr>
  3663.   Here <cr> means 'hit RETURN key'
  3664.   Then it will be displayed that
  3665. test
  3666. OK
  3667.   Next, try a calculation
  3668. print 123*456<cr>
  3669.   will induce
  3670.  56088
  3671. OK
  3672.  
  3673.   Now let's make a program.  The easiest program may be
  3674. 10   print "This is the 1st program."<cr>
  3675.   It is stored and is waiting for the execution command.
  3676.   Write
  3677. run<cr>
  3678.   then the program will run and it will be displayed that
  3679. This is the 1st program.
  3680. OK
  3681.  
  3682. ~~Lesson 2.
  3683. Lesson 2.
  3684.  
  3685.   We will make a longer program.
  3686.   Compute the sum from 1 to 100.
  3687.  
  3688.    10   Sum=0<cr>
  3689.    20   for I=1 to 100<cr>
  3690.    30     Sum=Sum+I<cr>
  3691.    40   next I<cr>
  3692.    50   print Sum<cr>
  3693.  
  3694.   The 'for' in the line 20 and the 'next' in line 40 are 
  3695. connected and are forcing to repeat the commands between them.
  3696.   Let's write
  3697. run<cr>
  3698.   then it will be appeared that
  3699.  5050
  3700. OK
  3701.  
  3702. ~~Lesson 3.
  3703. Lesson 3.    Big Number Arithmetic
  3704.  
  3705.   Lessons 1 and 2  can be done by any other computer languages.  
  3706. UBASIC can handle very big numbers.  For example, let's compute
  3707.  the product from 1 to 100.
  3708.  
  3709. 10   Product=1
  3710. 20   for I=1 to 100
  3711. 30     Product=Product*I
  3712. 40   next
  3713. 50   print Product
  3714. run
  3715.  93326215443944152681699238856266700490715968264381621468592963
  3716. 895217599993229915608941463976156518286253697920827223758251185
  3717. 210916864000000000000000000000000
  3718. OK
  3719.   If one wants to calculate this by usual BASIC language, he 
  3720. must make a long and complicated program.
  3721.  
  3722. ~~Lesson 4.
  3723. Lesson 4.    User Defined Functions
  3724.  
  3725.   This time compute a sum of powers, namely 
  3726.   1^3+2^3+...+100^3 or 11^4+12^4+...+50^4  etc.
  3727.   Write the power by 'Power', the start number by 'Start' and 
  3728. the final number by 'Final', then the program may be
  3729.  
  3730. 10   Power=3:Start=1:Final=20
  3731. 20   Sum=0
  3732. 30   for I=Start to Final
  3733. 40     Sum=Sum+I^Power
  3734. 50   next
  3735. 60   print Sum
  3736.   Let's execute this.  Then 1^3 + 2^3 + ... + 20^3 will be 
  3737. computed and the result will be displayed:
  3738. run
  3739.  44100
  3740. OK
  3741.   We remake it to a function to use again.
  3742.  
  3743.  5   fnPowerSum(Power,Start,Final)
  3744. 10     local Sum,I
  3745. 20     Sum=0
  3746. 30     for I=Start to Final
  3747. 40       Sum=Sum+I^Power
  3748. 50     next
  3749. 60   return(Sum)
  3750.   Rewrite the lines 10 and 60, and add the line 5.  The 
  3751. returning value is assigned by writing in () after RETURN.
  3752.  
  3753.   Now we got our function PowerSum.
  3754.   To try it, write
  3755. print fnPowerSum(22,1,100)
  3756.   then  1^22 + 2^22 + ... + 100^22  will be computed and the 
  3757. result is
  3758.  
  3759.  486614659739941950597622922368810419475443850
  3760. OK
  3761.   We can use user_functions from the direct mode if it is in 
  3762. the memory.
  3763.   Store this to the disk.
  3764. save "PowerSum"
  3765. OK
  3766.   Let's exit from UBASIC once.
  3767. system
  3768.   will return us to MS-DOS.
  3769.  
  3770.   Imagine some days after, you need to compute the sum of the 
  3771. 1-st, 2-nd,... 10-th powers of from 1 to 100.  Since you 
  3772. already have the function PowerSum, you can easily complete the
  3773.  work like this:
  3774.   Write the main program as follows:
  3775.  
  3776. 10   for I=1 to 10
  3777. 20     print I,fnPowerSum(I,1,100)
  3778. 30   next
  3779. 40   end
  3780.   Now we use the 'append' command.
  3781. append "PowerSum"
  3782. OK
  3783.   Then the 'PowerSum' function is loaded from the disk and 
  3784. linked to the last of the main program like this:
  3785.  
  3786. list
  3787.    10   for I=1 to 10
  3788.    20     print I,fnPowerSum(I,1,100)
  3789.    30   next
  3790.    40   end
  3791.  1040   fnPowerSum(Power,Start,Final)
  3792.  1050     local Sum,I
  3793.  1060     Sum=0
  3794.  1070     for I=Start to Final
  3795.  1080       Sum=Sum+I^Power
  3796.  1090     next
  3797.  1100   return(Sum)
  3798. OK
  3799.   Please note the line numbers automatically renumbered.  You 
  3800. need not care about the line numbers.
  3801.  
  3802. run
  3803.  1       5050
  3804.  2       338350
  3805.  3       25502500
  3806.  4       2050333330
  3807.  5       171708332500
  3808.  6       14790714119050
  3809.  7       1300583304167500
  3810.  8       116177773111333330
  3811.  9       10507499300049998500
  3812.  10      959924142434241924250
  3813. OK
  3814. <point>
  3815.   One who is familiar with normal BASIC languages will be 
  3816. confused by the usage of the variable 'I'.  Usual BASIC will 
  3817. run abnormally by such a program.  But UBASIC has local 
  3818. variables, the 'local' command in line 1050 preserves the value
  3819.  of 'I' in the main program and generate the new 'I' and 
  3820. initialize to 0.  The 'return' command will reset the original 
  3821. value to 'I'.
  3822.  
  3823. ~~Lesson 5.
  3824. Lesson 5.    Calculation of Real number
  3825.  
  3826.   To use the real numbers, one must set the precison by the 
  3827. 'point' command.
  3828.     point numerical_expression
  3829.   is the command format.  About 4.8 times the assigned value is
  3830.  the decimal digits.
  3831.  
  3832. point 10
  3833.   will set to 48 decimal digits.
  3834. OK
  3835. print 11/12
  3836.  0.916666666666666666666666666666666666666666666666
  3837. OK
  3838.  
  3839.  Calculate sin(X) from  X=1degree,...,45degrees by 20 decimals.
  3840.  Let's take POINT to be 5.
  3841.  
  3842.    10   point 5
  3843.    20   for I=0 to 45
  3844.    30     X=pi(I/180):'                     pi(I/180)=#pi*I/180
  3845.    40     print using(3),I;using(2,20),sin(X)
  3846.    50   next
  3847.  
  3848. run
  3849.   0  0
  3850.   1  0.01745240643728351282
  3851.   2  0.03489949670250097165
  3852.   3  0.05233595624294383272
  3853.   4  0.06975647374412530078
  3854.   5  0.08715574274765817356
  3855.   6  0.10452846326765347140
  3856.   7  0.12186934340514748111
  3857.   8  0.13917310096006544411
  3858.   9  0.15643446504023086901
  3859.  10  0.17364817766693034885
  3860. ...
  3861. OK
  3862.  Here 'print using(p1,p2)' assigns the display length of 
  3863. integer and fractional parts.
  3864.  
  3865. ~~Lesson 6.
  3866. Lesson 6.    High Precision Arithmetic
  3867.  
  3868.   Theoretically, (1+1/N)^N  converges to  'e'  as  N goes to 
  3869. infinity.  Let's see this numerically.
  3870.  
  3871.    10   point 20
  3872.    20   N=100:print (1+1/N)^N
  3873.    30   N=10^10:print (1+1/N)^N
  3874.    40   N=10^50:print (1+1/N)^N
  3875.  
  3876. run
  3877.  2.704813829421526093267194710807530833677938382781002776890201
  3878. 049117101514306739279439456014346584
  3879.  2.718281828323131143949794001297229499885179933883965470815866
  3880. 244433899270751441490494848853547347
  3881.  2.718281828459045235360287471352662497757247093625082984984087
  3882. 392709574135039719662542902843924865
  3883. OK
  3884.   The exact value of 'e' is
  3885. ? #e
  3886.  2.718281828459045235360287471352662497757247093699959574966967
  3887. 627724076630353547594571382178525165
  3888. OK
  3889.  Thus we can see that this sequence converges very slow but 
  3890. steadily to 'e'.  Note when you try with larger N's, set the 
  3891. point to be larger than 1/3 of the decimal digits of  N.
  3892.  
  3893. ~~Lesson 7.
  3894. Lesson 7.    Output Redirection
  3895.  
  3896. ü@There are two ways to store the calculation results to the 
  3897. disk.
  3898.   Here we use one of them, 'output redirection'.
  3899.  
  3900. ü@print=print+"file name"
  3901.  
  3902.   assigns the output device of the print command to CRT and the
  3903.  file.  For example, let's use the program in the Lesson5.
  3904.   Write before 'run'
  3905. print=print+"sin"
  3906. OK
  3907. run
  3908. OK
  3909.  Note this time the disk will work.
  3910.  
  3911. print=print
  3912. OK
  3913.   sets to the normal mode.
  3914.   Let's return to MS-DOS.
  3915.  
  3916. system
  3917. A>dir
  3918.   You will find the file 'sin', you will be able to edit it 
  3919. with your editor and print it beautifully.
  3920.   The variation:
  3921.   print=lprint
  3922.   print=print+lprint+"xyz"
  3923.   lprint=print
  3924.   etc.
  3925.  
  3926. ~~Lesson 8.
  3927. Lesson 8.    Arithmetic of Complex Numbers
  3928.  
  3929.   UBASIC version 8 can treat complex numbers like as real 
  3930. numbers.
  3931.   The unit of the imaginary number(square root of -1) is 
  3932. denoted by  #i.
  3933.   Let's make a function which answers one of the solutions of 
  3934. a quadratic equation.
  3935.   The well-known formula tells:
  3936.  
  3937. 10   fnQuadraEq(A,B,C)
  3938. 20     local D,Sol
  3939. 30     D=B^2-4*A*C
  3940. 40     Sol=(-B+sqrt(D))/(2*A)
  3941. 50   return(Sol)
  3942.  
  3943. ? .QuadraEq(1,2,3)
  3944. -1.0+1.4142135623730950487#i
  3945. OK
  3946.  Here  ?  is the shortened form of 'print' and  .  is that of 
  3947. 'fn'.
  3948.  
  3949.   Complex numbers can be used for the power arithmetic.  Let's 
  3950. think what is 'i' to the 'i'-th power?
  3951.  
  3952. ? #i^#i
  3953.  0.2078795763507619085
  3954. OK
  3955. is the answer. Since 'i' is the 'e' to the 'pi'/2*'i'-th power,
  3956.  'i' to the 'i'-th power must be the 'e' to the  -'pi'/2-th 
  3957. power.
  3958.  
  3959. ? exp(-pi(1/2))
  3960.  0.2078795763507619085
  3961. OK
  3962. Surely!
  3963. (You can use other expressions for exp(-pi(1/2)) such as 
  3964. exp(-#pi/2), #e^(-pi(1/2)) or #e^(-#pi/2), but I recommend 
  3965. exp(-pi(1/2)) most.)
  3966. Since a power function is multivalued, we must determine what 
  3967. branch UBASIC uses.  First UBASIC interprets #i^#i = 
  3968. exp(log(#i)*#i). And log(#i) = atan(1,0)*#i.  Finally two 
  3969. valiable arctangent takes its value larger than -pi less or 
  3970. equal to pi.
  3971.  
  3972. ~~Lesson 9.
  3973. Lesson 9.    Passing functions as parameters
  3974.  
  3975.   Suppose you are making a function or a subroutine which is 
  3976. applicable to various functions or subroutines.  You cannot use
  3977.  the exact function name in the program.  It may be convenient 
  3978. to use an abstract function name in your subroutine and get the
  3979.  exact function name as a parameter from the main routine.
  3980.   See the following example.  The function fnSimpson defined in
  3981.  the lines 140-230 gives an integration of the function fnF 
  3982. from A to B by N steps.
  3983. Lines 10-20 show the usage.
  3984.   You can do this only for the user defined functions.  The 
  3985. built_in functions cannot be passed directly.
  3986.  
  3987.    10   print fnSimpson(&fnA,0,1,1/10^6)
  3988.    20   print fnSimpson(&fnB,0,1,1/10^6)
  3989.    30   end
  3990.    40   '
  3991.    50   fnA(X)
  3992.    60   return(1/(1+X^2))
  3993.    70   '
  3994.    80   fnB(X)
  3995.    90   return(sqrt(1-X^2))
  3996.   100   '
  3997.   110   'Simpson's Rule (Numerical Integration)
  3998.   120   ' program from the book:
  3999.   125   ' S.Moriguchi Suuchi Keisan Jutu (Kyoritu Syuppan)
  4000.   130   '
  4001.   140   fnSimpson(&fnF(),X1,X2,E1)
  4002.   150     local Dy,H,M,N,S0,S1,S2,Y1,Y2
  4003.   160     N=2:H=(X2-X1)/N
  4004.   170     S0=fnF(X1)+fnF(X2):S1=fnF(X1+H):S2=0
  4005.   180     Y1=(S0+4*S1)*H/3
  4006.   190     repeat
  4007.   200       N=N*2:H=H/2:S2=S1+S2:S1=0
  4008.   210       for M=1 to N step 2:S1=S1+fnF(X1+M*H):next
  4009.   220       Y2=(S0+4*S1+2*S2)*H/3:Dy=Y2-Y1:Y1=Y2
  4010.   230     until absmax(Dy)<E1
  4011.   240   return(Y2)
  4012.  
  4013. run
  4014.  0.7853981628062055473
  4015.  0.7853977254182970949
  4016. OK
  4017.  
  4018.   Also subroutines can be passed as parameters.
  4019.  
  4020.    10   gosub *Test(&*A)
  4021.    20   gosub *Test(&*B)
  4022.    30   end
  4023.    40   '
  4024.    50   *A
  4025.    60     print "Now in A."
  4026.    70   return
  4027.    80   '
  4028.    90   *B
  4029.   100     print "Now in B."
  4030.   110   return
  4031.   120   '
  4032.   130   *Test(&*X)
  4033.   140     gosub *X
  4034.   150   return
  4035.  
  4036. run
  4037. Now in A.
  4038. Now in B.
  4039. OK
  4040.  
  4041. ~~Lesson 10.
  4042. Lesson 10.    Arithmetic of Rational Numbers
  4043.   UBASIC version 8 can treat rational numbers.  Write the 
  4044. numerator 1st, next the operator // and the denominator.  For 
  4045. example, 2//3 denotes '2 over 3'.
  4046. The rational number is stored in the reduced form. For example,
  4047.  2//4 is stored as 1//2, 3//1 is stored as 3(=integer).
  4048.   The following program will give the rational approximation of
  4049.  'e', the error will be smaller than 655536^(-21).
  4050.  
  4051.    10   'rational calculation of E
  4052.    20   point 21
  4053.    30   E#=0:I=1:W#=1
  4054.    40   while cvr(W#)
  4055.    50     E#=E#+W#:W#=W#//I:I=I+1
  4056.    60   wend
  4057.    70   print num(E#)
  4058.    80   print "/"
  4059.    90   print den(E#)
  4060.   100   print
  4061.   110   print cvr(E#)
  4062.   120   end
  4063.  
  4064. ~~Lesson 11.
  4065. Lesson 11.    Arithmetic of 1 variable polynomials
  4066.   UBASIC version 8 can treat polynomials of 1 valiable.
  4067. For example the polynomial 1+x+2*x^3 is denoted in UBASIC by  
  4068.   F#=poly(1,1,0,2)  or  
  4069.   F#=1+_x+2*_x^3    or  
  4070.   F#=poly(1):coeff(F#,1)=1:coeff(F#,3)=2
  4071. Either will produce the same result.
  4072.  
  4073.   The following program will give the differential of the 
  4074. polynomial.
  4075.  
  4076.    10   'differential
  4077.    20   input F#
  4078.    30   DF#=0
  4079.    40   for I=1 to deg(F#)
  4080.    50     coeff(DF#,I-1)=I*coeff(F#,I)
  4081.    60   next
  4082.    70   print DF#
  4083.    80   end
  4084.  
  4085. ~~Lesson 12.
  4086. Lesson 12.    Packing multiple data
  4087.   When you treat the data which consists of multiple sub_data, 
  4088. what do you do?
  4089. If you are a user of Pascal, you can use the 'record type' but 
  4090. you cannot make a function which returns such data.  If you are
  4091.  a user of an ANSI C, you can define a function which returns 
  4092. the 'struct'ured data.  UBASIC has no such data structure but 
  4093. can treat a set of data usually called a 'list'(in UBASIC 
  4094. called a 'pack') and can return that as the value of the 
  4095. functions.
  4096.   The following program will give the prime factorization of 
  4097. natural numbers.
  4098.  
  4099.    10   'prime factorization
  4100.    20   input "Integer <= 100000 =";N
  4101.    30   if N>100000 then beep:goto 20
  4102.    40   W#=fnFactor(N)
  4103.    50   for I=1 to len(W#)
  4104.    60     Ww#=member(W#,I)
  4105.    70     print member(Ww#,1);
  4106.    80     Power=member(Ww#,2)
  4107.    90     if Power>1 then print "^";Power;
  4108.   100     if I<len(W#) then print " * ";
  4109.   110   next
  4110.   120   print
  4111.   130   end
  4112.   140   '
  4113.   150   fnFactor(N)
  4114.   160     local P,Pold,E:W#=pack()
  4115.   170     Pold=prmdiv(N):N=N\Pold:E=1
  4116.   180     repeat
  4117.   190       P=prmdiv(N):N=N\P
  4118.   200       if P=Pold then E=E+1:goto 190
  4119.   210       W#=W#+pack(pack(Pold,E))
  4120.   220       Pold=P:E=1
  4121.   230     until P=1
  4122.   240   return(W#)
  4123.  
  4124. ~~Lesson 13.
  4125. Lesson 13.   Manipulation of strings
  4126.   You can use almost all commands and functions which are 
  4127. equipped by the usual BASIC languages such as RIGHT(),MID(),
  4128. LEFT(),...
  4129.   One advantage was added for UBASIC version 8.  That is, you 
  4130. can compute the string if it represents a mathematical formula.
  4131.   Moreover, you can execute the string if it represents a 
  4132. UBASIC command.
  4133.   The following program will make a table of the function which
  4134.  you assigned from the keybord.
  4135.  
  4136.    10   'table of a function
  4137.    20   print "Input a function using x as a variable (ex. 
  4138.         sin(x), x+cos(x),...)"
  4139.    30   strinput F#
  4140.    40   F#=encode(F#)
  4141.    50   for I=0 to 20
  4142.    60     X=I/20
  4143.    70     print using(4,4),X,using(4,6),val(F#)
  4144.    80   next
  4145.    90   end
  4146.  
  4147. ~~PrimeTests
  4148. Primality tests and factorization of integers are discussed,
  4149. e.g., in
  4150.  
  4151.     S. S. Wagstaff, Jr. and J. W. Smith:  Methods of Factoring
  4152.     Large Integers.  Springer Lecture Notes in Mathematics, No.
  4153.     1240, pp. 281-303
  4154.  
  4155.     Hideo Wada: Suugaku 38 (1986), pp. 345-350 (in Japanese).
  4156.  
  4157. PRTEST1 is an implementation of Lenstra's version of the
  4158. Adleman-Pomerance-Rumely primality test algorithm.  It is
  4159. faster than simple-minded ones for integers of more than 12 to
  4160. 13 figures.  A 70-figure number can be tested in an hour.  A
  4161. present implementation can handle integers of up to 137 figures.
  4162. See
  4163.  
  4164.     L. M. Adleman, C.Pomerance and R. S. Rumely:
  4165.     On Distinguishing Prime Numbers from Composite Numbers.
  4166.     Ann. of Math. 117(1983), pp.173-206.
  4167.  
  4168.     H. W. Lenstra, Jr.: Primality Testing Algorithm.
  4169.     Springer Lecture Notes in Mathematics No. 901, pp. 243-257.
  4170.  
  4171.     Hideo Wada:  Kousoku Jousan Hou to Sosuu Hantei Hou.
  4172.     Sophia University Mathematics Lecture Note No. 15,
  4173.     pp. 131-153 (in Japanese).
  4174.  
  4175. PRTEST1 follows Wada's presentation (but does not replace his
  4176. Condition 2 by Condition 7).
  4177.  
  4178. Cohen and Lenstra have improved the algorithm by using Jacobi
  4179. sums:
  4180.  
  4181.     H. Cohen and H. W. Lenstra, Jr.:  Primality Testing and
  4182.     Jacobi Sums.  Mathematics of Computation 42 (1984), 297-330.
  4183.  
  4184.     H. Cohen and A. K. Lenstra:  Implementation of a New
  4185.     Primality Test.  Mathematics of Computation 48 (1987),
  4186.     103-121.
  4187.  
  4188. APRT-CL implements their algorithm.  It is faster than PRTEST1
  4189. and can test numbers of up to 300 figures.
  4190.  
  4191. ~~Factorize
  4192. ECM, ECMX -- ECM factors integers using the Elliptic Curve
  4193. Method.  In a reasonable time, it can handle integers of more
  4194. than 200 figures, but with a factor of at most 20 figures.
  4195. ECMX, which uses a machine language routine, is faster by a few
  4196. per cent.  The original account of the algorithm is given by
  4197.  
  4198.     H. W. Lenstra, Jr.:  Factoring Integers with Elliptic
  4199.     Curves.  Annals of Mathematics 126 (1987), 649-673.
  4200.  
  4201. The following is handy when implementing the method.
  4202.  
  4203.     P. L. Montgomery:  Speeding the Pollard and Elliptic Curve
  4204.     Methods of Factorization.  Mathematics of Computation 48
  4205.     (1987), 243-264.
  4206.  
  4207. MPQSX uses the Multiple Polynomial Quadratic Sieve method.  It
  4208. can factor integers of up to about 45 figures.  Increase the
  4209. multiple of 16 on line 880 as far as the memory allows:
  4210.  
  4211.     16*30: 40 figures can be factored
  4212.     16*50: 45 figures can be factored
  4213.  
  4214. A 30-figure number takes 4 minutes; 35-figure, 9 minutes;
  4215. 40-figure, 20 minutes; 45-figure, an hour.
  4216.  
  4217. This routine uses machine language.  Its source listing is in
  4218. the MPQS#10.ASM file.
  4219.  
  4220. See:
  4221.  
  4222.     R. D. Silverman:  The Multiple Polynomial Quadratic Sieve.
  4223.     Mathematics of Computation 48 (1987), 329-339.
  4224.  
  4225. If you have 32-bit machines(CPU=386DX,386SX,486) with more than
  4226. 1MBytes extended memories and 10-100MBytes Hard Disk free area,
  4227. try MPQSHD in the MPQS32-subdirectory, which will decompose up
  4228. to 80 digits(it will take more than 1000hours).
  4229.  
  4230. MPQS and ECM are the newest and fastest integer factoring
  4231. methods.  But they work quite differently.  MPQS is more
  4232. predictable but cannot handle large numbers.  It would take
  4233. several months to factor a 100-figure number even with a
  4234. supercomputer.  ECM is quite fast when the number has a small
  4235. factor:  A 100-figure number with factors of no more than 20
  4236. figures can be factored in a reasonable time.
  4237.  
  4238. If the number has more than 55 figures, use ECM and hope for
  4239. luck! There's no way to tell beforehand how long it will take.
  4240. For smaller numbers, use MPQS.
  4241.  
  4242. Recently a new factorization method was invented, which was
  4243. named the Number Field Sieve method.  This method can be applied
  4244. only for the special kind of integers until now.
  4245.   A.K.Lenstra, H.W.Lenstra,Jr., M.S.Manasse and J.M.Pollard:
  4246.   The number field sieve (preprint).
  4247. They decomposed C148 of 2^(2^9)+1 into P49*P99.
  4248.  
  4249. POLFACT -- Factorize one variable polynomial in rational
  4250. numbers.
  4251.  
  4252. POLFACT1, POLFACT2 -- Both decompose a one-variable polynomial
  4253. into a product of irreducible ones modulo a prime number.
  4254. POLFACT1 reports only the decomposition type and the number of
  4255. factors with multiplicities for each degree.  POLFACT2 finds a
  4256. complete set of irreducible factors but runs slower.
  4257.  
  4258. ~~NumTheory
  4259. UNITR2, REALQF, REALQF2 -- UNITR2 computes fundamental units of
  4260. real quadratic fields, i.e., solutions of Pell equations.  It
  4261. will suffice if class numbers are not needed.  REALQF is a
  4262. straightforward implementation of the flowchart in
  4263.  
  4264.     H. Wada:  Table of Class Numbers of Real Quadratic Fields.
  4265.     Sophia University Mathematics Lecture Note No. 10
  4266.  
  4267. with an added routine to compute fundamental units.  It is much
  4268. faster and more reliable than REALQF2.
  4269.  
  4270. REALQF2 determines class numbers by an analytic formula.  It is
  4271. only approximate; the results are rounded to the nearest
  4272. integer.  When the discriminant is large, increase the POINT
  4273. value to cope with error.
  4274.  
  4275. IMAGQF, IMQF -- IMAGQF finds the class numbers of imaginary
  4276. quadratic fields analytically as character sums:
  4277.  
  4278.   110   D=4*N:if N@4=3 then D=D\4
  4279.   115   H=0
  4280.   120   for X=1 to D\2
  4281.   130     H=H+kro(-D,X)
  4282.   140   next X
  4283.   150   H=H\(2-kro(-D,2))
  4284.   160   print "Class Number is  ";H
  4285.  
  4286. IMQF counts points in the fundamental region on the complex
  4287. plane. It is much faster than IMAGQF.
  4288.  
  4289. GENSHI, GENSHIP -- These compute minimum primitive roots and
  4290. minimum prime primitive roots modulo P.
  4291.  
  4292.    10   'GENSHI version 1.2
  4293.    20   print "Primitive Root modulo P"
  4294.    30   input "Prime = ";P
  4295.    40   if P<3 then print "Too small":goto 30
  4296.    50   if P>=65536^2 then print "Too big":goto 30
  4297.    60   if prmdiv(P)<P then print "Not prime":goto 30
  4298.    70   G=2:N=P-1
  4299.    80   NW=N
  4300.    90   D=prmdiv(NW)
  4301.   100   repeat:NW=NW\D:until res:NW=NW*D+res
  4302.   110   if modpow(G,N\D,P)=1 then inc G:goto 80
  4303.   120   if NW>1 then goto 90
  4304.   130   print G;"is the smallest primitive root MOD";P
  4305.   140   end
  4306.  
  4307. KAIJOU (factorial) -- An example program to illustrate UBASIC86's
  4308. output formatting.
  4309.  
  4310.    10   'KAIJOU version 1.1
  4311.    20   word 510
  4312.    30   print "Factorials"
  4313.    40   F=1
  4314.    50   for N=1 to 20
  4315.    60     F=F*N
  4316.    70     print using(5),N;"! =";using(25),F
  4317.    80   next N
  4318.    90   end
  4319.  
  4320. ~~aboutUB
  4321. about UBASIC
  4322.  
  4323. UBASIC is written by
  4324.     Prof. Yuji Kida
  4325.     Department of Mathematics
  4326.     Rikkyo University
  4327.     Nishi-Ikebukuro 3, Tokyo 171, JAPAN.
  4328.     (e-mail: kida@rkmath.rikkyo.ac.jp
  4329.              X032991@JPNRKY00.BITNET)
  4330.  
  4331.   If you find any bug, please inform me at the address above.
  4332. Application programs written in UBASIC are also welcome.
  4333.  
  4334.   I welcome your copying and distributing this software,
  4335. magnetically or otherwise.
  4336.  
  4337.   This software is distributed as is.  I disclaim all
  4338. warranties, expressed or implied.  I assume no liability for
  4339. damages, direct or consequential, which may result from the
  4340. use of this software.
  4341.  
  4342.   Here I express my hearty thanks to the users who told me the
  4343. bugs and suggested me the improvements, especially,
  4344. Prof.s Shigeki Egami, Mituo Morimoto in Japan, Dr. Frank O'Hara
  4345. in England and Prof. Walter Neumann in USA.
  4346.  
  4347.   This manual is written, translated and revised by
  4348.     Prof. Yuji Kida,
  4349.     Mr. Haruhiko Okumura, 
  4350.     Mrs. Yoko Iwase in Japan,
  4351.     Dr. Frank O'Hara in England and
  4352.     Prof. Walter Neumann in USA.
  4353.  
  4354.   This on-line manual system is created by
  4355.     Prof. Yoichi Koyama in Japan.
  4356.  
  4357.  Version 8.30.  January 5, 1992.
  4358. --------------------------------------------------------------
  4359. 
  4360.